I was wonder if in JQuery, this is possible:
<form id="testform">
<input type="text" id="hi" name="hi" />
<input type="text" id="bye" name="bye" />
<button type="submit" id="submit1">Use Me</button>
<button type="submit" id="submit2">No, Use Me </button>
</form>
$('#testform').submit(function(e) {
e.preventDefault();
var submiturl;
if (e.name === 'submit1') { submiturl = '../sendToFactory.cshtml'; }
else if (e.name === 'submit2') { submiturl = '../sendOverseas.cshtml'; }
$.ajax({
url: submiturl,
data: $('testform').serialize(),
type: 'POST',
datatype: 'json',
success: function (response) {
//stuff
},
error: function (response) {
//error
}
});
});
I know the e.name
isn't right, but there must be someway to do something similar to that, no?
And I'm using IE9 and above.
click
events on submit buttons instead of formsubmit
event – Dolli