I have this ‘web service’ I made that when accessed:
"http://192.168.0.1/api/v1/search/?query=thequery"
returns a JSON string as the result. Its very simple it just return string.
I am trying to access it from my client site using JQuery:
function doSearch() {
$.ajax({
url: "http://192.168.0.1/api/v1/search/?query=" + $('#searchfield').val(),
dataType: 'jsonp',
success: function(json_results){
alert('Alert title', 'Alert message!');
},
error: function() {
alert('Error', 'Alert message!');
}
});
}
Although I when the web service return properly when accessed with curl or the web browser, when accessed through $.ajax it always fail, showing the Error alert message box.
EDIT: From Firebug console I get:
Content-Type application/json; charset=utf-8
Content-Length 131
Connection keep-alive
However, the reponse is empty.
You don’t have a JSONP service; you’re just returning JSON.
So, use the proper
datatype: