views:

123

answers:

3

I'm using JQuery to make an Ajax call. I used a sniffer to catch the response text:

{"error_code":0,"message":"SUCCESS","data":{"session_token":"3efd9dde-a839-4e91-9415-4c2f6cba5b7b"}}

But the response returned on the success callback is null. Anyone got any ideas? (see jquery code below.

Jquery code:

  $.ajax({
   type: "GET",
   url: "http://184.72.58.99/matchaapi/API/User/Login",
   data: { email: emailval, password: pwordval, developer_key: devkey },
   dataType: "json",
   cache: false,
   beforeSend: function(xhr) {
                           xhr.setRequestHeader( "Content-Type", "application/json; charset=utf-8" );
                       },
   success: function(resp) {
      alert(resp);
      $("#status p").html(resp.message);
     }});
+1  A: 

What version of jQuery, and what browser? Try binding to the complete event rather than the success event.

Stefan Kendall
+1 - If I remember correctly, `complete` returns a response, whereas `success` doesn't.
Jud Stephenson
thanks for the quick replies:firefox 3.6.2 and safari 4.0.4jquery 1.4.2complete only returns the text status and request object, not the response. (i tried it.)
Paul Petrick
+1  A: 

According to the jQuery API docs:

The [success] function gets passed three arguments: The data returned from the server, formatted according to the 'dataType' parameter

Maybe the data isn't formatted as proper JSON?

Raul Agrait
+3  A: 

Just a guess... is your site being served from the same site as the API you are trying to call? You can't make an AJAX request to another server directly from the browser unless you use JSONP (see jsonp parameter in jQuery.ajax()). If the API doesn't support it then you will need to proxy the calls through your web server.

Lance McNearney
yup. that was it. completely forgot about this. thanks so much!
Paul Petrick
Great. Can you do me a favor hit the green "accept" checkmark next to the answer? Welcome to Stack Overflow!
Lance McNearney