Doua actiuni cu un singur buton intrun formular
Scris: Mie Apr 20, 2016
Salut,
Am un formular cu ajax
in <div id="simple-msg"> </div> imi afiseaza rezultatul
iar in .JS am
Cum pot ca atunci cand dau click pe butonul CALCULEAZA imi va afisa calculul, dar sa ma mai trimita si pe o alta pagina sa imi faca alte calcule,etc dar tot prin ajax, deci sa nu se deschida in browser nimic
Multumesc
Am un formular cu ajax
Cod: Selectaţi tot
<form method='POST' name="ajaxform" id="ajaxform" action="rezultat.php">
<table>
<tbody>
<tr>
<td> Suprafata (mp): </td>
<td><input type='text' class='suprafata' name='suprafata' value=''> </td>
</tr>
<tr>
<td> Grosime (5 - 30 cm): </td>
<td> <input type='text' class='grosime' name='grosime' value=''> </td>
</tr>
<tr>
<td> Densitate (30 - 60 kg/mc): </td>
<td> <input type='text' class='densitate' name='densitate' value=''> </td>
</tr>
<tr>
<td> Distanta (Km): </td>
<td> <input type='text' class='distanta' name='distanta' value=''> </td>
</tr>
<tr>
<td> Folie interior: </td>
<td> <select class='folie-int' name='folie-int' >
<option value="">selecteaza</option>
<option value="1">Da</option>
<option value="0">Nu</option>
</select>
</td>
</tr>
<tr>
<td> Folie exterior: </td>
<td> <select class='folie-ext' name='folie-ext' >
<option value="">selecteaza</option>
<option value="1">Da</option>
<option value="0">Nu</option>
</select>
</td>
</tr>
<tr>
<td> EURO: </td>
<td> <input type='text' class='euro' name='euro' value='<?php echo $euro ?>'> </td>
</tr>
<tr>
<td>
<br> <input type='button' value='CALCULEAZA' class='boton' name='boton' id='simple-post' > </td>
</tr>
</tbody>
</table> <br>
<div id="simple-msg"> aici imi afiseaza rezultatul </div>
</form>
iar in .JS am
Cod: Selectaţi tot
$("#ajaxform").submit(function(e)
{
$("#simple-msg").html("<img src='ajax-loader.gif'/>");
var postData = $(this).serializeArray();
var formURL = $(this).attr("action");
$.ajax(
{
url : formURL,
type: "POST",
data : postData,
success:function(data, textStatus, jqXHR)
{
$("#simple-msg").html(''+data+'');
},
error: function(jqXHR, textStatus, errorThrown)
{
$("#simple-msg").html('AJAX Request Failed<br/> textStatus='+textStatus+', errorThrown='+errorThrown+'');
}
});
e.preventDefault(); //STOP default action
e.unbind();
});
$("#ajaxform").submit(); //SUBMIT FORM
Multumesc