i am unable to get the response from ajax. please guide me how to resolve this error, i am getting successful data return from the server i have checked it in fiddle web debugger and still ajax is showing error. XML Parsing Error: no element found Location: moz-nullprincipal:{6b0a1ac2-50ab-4053-9f71-8ae49202288d} Line Number 1, Column 1:
$j.ajax({
type:"POST",
url:'http://www.w3schools.com/webservices/tempconvert.asmx/CelsiusToFahrenheit',
data: 'Celsius=12',
crossDomain:true,
async: false,
success:function(response)
{
alert("Success Full Done"+response.string);
},
beforeSend: function( xhr ) {
xhr.overrideMimeType( 'text/plain; charset=UTF-8' );
}
});
I've this problem with request:
$.ajax({
type: "POST",
url: ajaxUrl,
dataType : "json",
contentType: "application/json",
data: JSON.stringify(data),
success: function (data) {
...
}
});
Accept header in request is:
Accept application/json, text/javascript, */*; q=0.01
Response status is 200, but browser detect error and no success callback called
Fixed by remove dataType : "json":
$.ajax({
type: "POST",
url: ajaxUrl,
contentType: "application/json",
...
The only difference that accept header in request changed to:
Accept */*
But now success callback is called.
Add the "beforeSend" function into your AJAX call to override the acceptable response mime type.
Refer to the jQuery.ajax() documentation: http://api.jquery.com/jquery.ajax/
As of jQuery 1.5.1, the jqXHR object also contains the overrideMimeType() method (it was available in jQuery 1.4.x, as well, but was temporarily removed in jQuery 1.5). The .overrideMimeType() method may be used in the beforeSend() callback function, for example, to modify the response content-type header:
$.ajax({
url: "http://fiddle.jshell.net/favicon.png",
beforeSend: function( xhr ) {
xhr.overrideMimeType( "text/plain; charset=x-user-defined" );
}
})
.done(function( data ) {
if ( console && console.log ) {
console.log( "Sample of data:", data.slice( 0, 100 ) );
}
});
And:
Data Types
Different types of response to $.ajax() call are subjected to different kinds of pre-processing before being passed to the success handler. The type of pre-processing depends by default upon the Content-Type of the response, but can be set explicitly using the dataType option. If the dataType option is provided, the Content-Type header of the response will be disregarded.
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