3

I have an AJAX request:

$.ajax({
   url : "proxy.php",
   type : "POST",
   data : xmlData,
   contentType : "application/x-www-form-urlencoded",
   processData : false,
   success : function(data) {
       // success
   },
   error : function(data) {
       // error
   },    
});

Which is being answered by a PHP proxy:

header('Content-type: text/xml');
echo $someXmlResponse;
exit();

None of the callbacks are getting fired, neither the success nor the error.

This isn't the first time I've got this. What's going on?


Edit: some updates - trailing comma was not the issue, but thanks for pointing it out. Console shows no errors. Firebug shows request is sent and received properly. Request returns with status 200 OK, data returns correctly.


Thanks for all the help guys. All your feedback was in place. However none actually solved the issue. It looks like a bug in Firefox 4b5.

6
  • 2
    This calls for basic debugging first. Any error messages in the console? What does Firebug say - are requests actually getting fired? What status code do they return? What kind of data are you sending? Why the explicit content type? Commented Sep 12, 2010 at 17:51
  • Do you get any javascript errors in the console? Commented Sep 12, 2010 at 17:52
  • @Pekka - thanks for the comments. I updated the question, I should've mentioned all that data, but basic debugging obviously showed nothing. Callbacks are simply not fired. Commented Sep 12, 2010 at 19:31
  • 1
    @Yuval can you try the complete callback? Does that fire? How are you testing whether they fire, using an alert()? Commented Sep 12, 2010 at 19:35
  • 1
    Sometimes it helps to check the page in Chrome, it has much better error reporting than Firefox, in which javascript syntax errors in callbacks or generated functions are sometimes totally silent. Commented Sep 12, 2010 at 19:42

3 Answers 3

3

The behavior you are observing could happen if the server returns invalid XML that cannot be parsed. Try returning something that is guaranteed to be valid XML:

header('Content-Type: text/xml'); // <-- Notice the Content-Type header casing
echo '<foo/>';
exit();

Also you are setting the contentType to application/x-www-form-urlencoded, while your data parameter is called xmlData assuming XML. By setting the processData parameter to false you are indicating that the data should be posted as is and not automatically converted to application/x-www-form-urlencoded and still you indicate this content type in the request which seems contradictory.

Also if you expect XML from the server you could specify dataType: 'xml'.

So your request might look like this:

$.ajax({
    url: 'proxy.php',
    type: 'POST',
    contentType: 'text/xml',
    data: '<request/>',
    processData: false,
    dataType: 'xml',
    success: function(data) {

    },
    error: function(data) {

    }
});
Sign up to request clarification or add additional context in comments.

1 Comment

Darin, what exactly does the [data:'<request/>'] do here? Before, he was using that to send a value that I assume was held by a variable named 'xmlData' which you have replaced with '<request />'. What exactly happens here?
2

This may not be your issue, but is something that will cause problems in some versions of IE. You have a trailing comma after the error: callback.

Whether or not it is the issue, you should remove that.

$.ajax({
   url : "proxy.php",
   type : "POST",
   data : xmlData,
   contentType : "application/x-www-form-urlencoded",
   processData : false,
   success : function(data) {
       // success
   },
   error : function(data) {
       // error
   }  // <--- removed trailing comma
});

1 Comment

Thanks, but that's not the issue.
0

have you tried using 'dataType' instead of 'data'? a la:

Try:

$.ajax({
   url : "proxy.php",
   type : "POST",
   dataType : 'xml',
   contentType : "application/x-www-form-urlencoded",
   processData : false,
   success : function(xml) {
       // success
   },
   error : function(xml) {
       // error
   }  
});

2 Comments

No - obviously I have to post the xml data.
well, my apologies, you don't always need to send to receive and I wasn't clear on that since your php does not explicitly state that it's receiving anything, but still an oversight on my part. Anyway, then would you still not need to declare the dataType? Have you tried this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.