Reputation: 1
I try post data with REST API using jQuery AJAX. My code is below,
$.ajax({
url: 'myurl',
type: 'POST',
contentType: 'application/json; charset=utf-8',
data: JSON.stringify(jsonData),
dataType: 'jsonp',
success: function(responseData, textStatus, jqXHR) {
if (responseData.result == "true") {
$.mobile.changePage("#registersuccess",{transition:"slide"});
} else {
alert("kayıt başarısız");
}
}
});
I am monitoring with Explorer developer tools. I get this error message:
HTTP400: BAD REQUEST - The request could not be processed by the server due to invalid syntax.
GET - http:MyService?callback=jQuery111306711937631005869_1470230696599&[{"name":"","phoneNumber":"","password":""}]&_=1470230696600
What does this mean: &_=1470230696600
?
Upvotes: 0
Views: 1229
Reputation: 1
I solved Problem adding Server Site code ,
public class CORSFilter
implements ContainerResponseFilter {
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
throws IOException {
MultivaluedMap<String, Object> headers = responseContext.getHeaders();
headers.add("Access-Control-Allow-Origin", "*");
//headers.add("Access-Control-Allow-Origin", "http://podcastpedia.org"); //allows CORS requests only coming from podcastpedia.org
headers.add("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
headers.add("Access-Control-Allow-Headers", "X-Requested-With, Content-Type, X-Codingpedia");
}
}
Upvotes: 0
Reputation: 9735
Cache defaults to false
for JSONP requests (see dataType
in your code); the parameter _
is used to burst the cache. The value is the timestamp at the time of the request.
See jQuery docs at http://api.jquery.com/jQuery.ajax/
Upvotes: 1
Reputation: 427
Replace datatype
from jsonp
to json
.
You can read more about the difference between json
and jsonp
here What are the differences between JSON and JSONP?
Upvotes: 0