Reputation: 3514
My URL service hosted at Google App Engine return JSON content type.
The example URL is this, that works perfect in browser. Also validated from http://jsonlint.com.
I am using following jQuery.ajax call to get the response.
jQuery.ajax({
type: "get",
url: "http://trim-pk.appspot.com/do?url=http://www.google.com",
dataType: "json",
success: function(response) {
alert(response);
}
});
What's went wrong? Why I am not getting the response. It's null.
I have tried with contentType: "application/json; charset=utf-8"
and contentType: "application/json; charset=ISO-8859-1"
, but got 500.
Following is my Firebug output.
Upvotes: 0
Views: 3653
Reputation: 80340
:
and /
are reserved characters in Url and have a special meaning.
To use them in Url parameters, you must "Url encode" them. Browsers do that automatically.
In Javascript you must do this by hand via encodeURIComponent()
function. This should do the trick:
jQuery.ajax({
type: "get",
url: "http://trim-pk.appspot.com/do?url=" + encodeURIComponent("http://www.google.com"),
dataType: "json",
success: function(response) {
alert(response);
}
});
Update: replaced encodeURI
with encodeURIComponent
.
Upvotes: 0
Reputation: 35951
try
jQuery.ajax({
type: "get",
url: "http://trim-pk.appspot.com/do",
data: {
url: "http://www.google.com"
},
dataType: "json",
success: function(response) {
alert(response);
}
});
Upvotes: 0