JQuery AJAX callback not starting

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
   },    
});

The response is answered by the PHP proxy:

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

None of the callbacks start, neither success nor error.

This is not the first time I have received this. What's happening?


Edit: some updates - the trailing comma was not a problem, but thanks for pointing it out. The console does not show errors. Firebug indicates that the request has been sent and received correctly. The request is returned with a status of 200 OK, the data is returned correctly.


Thanks for helping everyone. All your reviews were in place. However, none of them solved the problem. It looks like a bug in Firefox 4b5.

+3
source share
3 answers

, , , XML, . -, XML:

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

contentType application/x-www-form-urlencoded, xmlData, XML. processData false, , application/x-www-form-urlencoded, , .

, XML , dataType: 'xml'.

, :

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

    },
    error: function(data) {

    }
});
+3

, , IE. error:.

, , .

$.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
});
+2

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
   }  
});
0
source

Source: https://habr.com/ru/post/1764389/


All Articles