Reputation: 29
Hi here is my code..
<html>
<head>
<script src="http://code.jquery.com/jquery-1.8.0.min.js">
</script>
</head>
<body>
<form id="foo">
<label for="bar">A bar</label>
<input id="bar" name="bar" type="text" value="" />
<input type="submit" value="Send" />
</form>
<div id ="onsuccess">
</div>
<script>
// variable to hold request
var request;
// bind to the submit event of our form
$("#foo").submit(function(event){
var $form = $(this);
var serializedData = $form.serialize();
request = $.ajax({
url: "a.txt",
type: "post",
dataType: "text",
data: serializedData,
success: function(){
console.log("yes, its successful");},
error : function(){console.log("got an error");}
});
});
</script>
</body>
</html>
i am trying to access a.txt which is in the same directory.But the success and error function never calls up which is not understandable. Firebug net status shows that no calls were made.strange
however if i use
request.done(function (response, textStatus, jqXHR){
// log a message to the console
console.log("Hooray, it worked!");
//$("#success").html(response);
});
it does work.
Upvotes: 0
Views: 1470
Reputation: 2809
Need to add this to submit handler
event.preventDefault()
Also changing POST to GET works for me on IIS
Upvotes: 1
Reputation: 8293
Try .done,.fail and .always
The success and error callbacks were deprecated in jquery 1.8
Deprecation Notice: The jqXHR.success(), jqXHR.error(), and jqXHR.complete() callbacks are deprecated as of jQuery 1.8. To prepare your code for their eventual removal, use jqXHR.done(), jqXHR.fail(), and jqXHR.always() instead.
Upvotes: 0