I have a jquery AJAX request calling a webservice with the result string being returned = “Tested!”. WHen I do the request though the url, it returns: {“testResult”:”Tested!”} which makes sense to me.
My error is that the jQuery AJAX request, will hit the webservice, hit a breakpoint, and return string, but then still hit the error code instead of success.
The error code is as follows:
//function(xhr,status,message)
xhr.statusText = success
status = parseerror
message: Error Jquery17204... was not called.
Below is my AJAX request. Maybe there is something wrong which i am not getting, which is causing the returned code to error.
$.ajax({
type: 'GET',
url: WEBSERVICE_URL + '/test',
dataType: 'jsonp',
success: function (result, textStatus, jqXHR) {
//success
result = JSON.parse(result);
var r = $(result.getWebFormDesignFieldContentsResult)[0];
var div = $("<div class='modal'>").html(r.d);
/*
var d = document.createElement("div");
d.className = "modal";
d.appendChild(r[0]);
*/
$("div.modal").replaceWith(div);
$("div.modal #queryInput").val(opts);
$("div.modal").css({
top: $(window).height() / 2 - $("div.modal").height() / 2,
left: $(window).width() / 2 - $("div.modal").width() / 2
});
$("div.modal").fadeIn();
},
error: function (xhr, status, message) {
//error
//alert("Error: "+result.statusText);
alert("Error: " + status + " " + message);
//$("div.modal").replaceWith($("<div class = 'modal'>").html(result.responseText));
//$("div.modal").fadeIn();
$("div.overlay").fadeOut();
}
});
You are making a JSONP call, so the result returned from the server has to look like this:
The server should take the query string
callbackand use as the function name. In this case the AJAX request sentcallback=Jquery17204.