I have the following bit of code which I'm just trying out by running in firebug
$.ajax({ type:"POST", url:"http://mpdomain/WebService.asmx/Operation", data: "{'parameter1': '44906'}", contentType: "application/json;charset=utf-8", dataType: "json", success: function(data) { alert("succsess") }, error: function(e, ts, et) { alert(ts) } })
In theory it should work. However the error handler is triggered, and ts is simply set to "error". How do I get more detail about what's gone wrong?
ajax() : $. ajax({ type: 'POST', url: 'page. php', data: stuff, success: function( data ) { }, error: function(xhr, status, error) { // check status && error }, dataType: 'text' });
You can show your loader / waiting image in ajax request in this way. $('#loading-image'). show(); $. ajax({ url: uri, cache: false, success: function(html){ $('.
Whenever an Ajax request completes with an error, jQuery triggers the ajaxError event. Any and all handlers that have been registered with the . ajaxError() method are executed at this time. Note: This handler is not called for cross-domain script and cross-domain JSONP requests.
To see the error message from an AJAX request, you can do something like this:
$.ajax({ type:"POST", url:"http://mpdomain/WebService.asmx/Operation", data: "{'parameter1': '44906'}", contentType: "application/json;charset=utf-8", dataType: "json", success: function(data) { alert("success") }, error: function(ts) { alert(ts.responseText) } // or console.log(ts.responseText) });
Note that, inside the error function, you get the responseText
.
The error message jQuery gives you is not very descriptive. It can either be "timeout", "error", "notmodified" or "parsererror." http://api.jquery.com/jQuery.ajax/ so what you can conclude is that it's not a timeout, not modified or parse error that you are getting.
Make sure in Firebug you see the request set to the correct address and the correct data is being set. You can also view the response so if you also have access to the server code a quick and dirty way is just to echo what is going on server side and view the response with Firebug.
Also I'm not sure if this is an issue but try to set the data to {parameter1: 44906} (basically remove the quotes so you are passing in an object and not a string).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With