views:

69

answers:

2

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?

+1  A: 
$.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(ts) { alert(ts.responseText) }
})
hmm - it's blank. Any ideas?
George Mauer
hmm...try responseStatus
why alerts, they are no good to anyone. use a debugger; statement or console.dir the object. Anything but alerts!
redsquare
Alerts because I'm running this straight out of the firebug console, just to see if I get the syntax right. I suppose console.debug would work just as well
George Mauer
+2  A: 

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).

jcmoney