Skip to content Skip to sidebar Skip to footer

Sending Ajax Request With A Rest Works But Not With Jquery

I'm trying to send an ajax call. I used a REST test extension for Chrome called Postman [Link to it]. When I send the call with the extension it works, but when I send it via jQuer

Solution 1:

If your data property is a JavaScript object, jQuery converts it to form data for transmission. It's possible that Postman is sending it as an actual string. Try wrapping your data in single quotes:

data: '{"sitename": "AAGx", "zone": 12, "sector": 34, "square": 7}', ...

Edit: In response to your edits, I can almost guarantee you it is a CORS, or cross-origin resource sharing, issue. AJAX and JavaScript in general are subject to various security constraints. One of the most central security concepts that limits the abilities of JavaScript is the Same Origin Policy. The idea is to prevent XSS (cross-site scripting) attacks.

jQuery's AJAX function will give an error code of 0 if it experiences CORS issues.

There's a detailed answer about how local files are under more strict security constraints here that explains your situation perfectly.

Your solutions are to send the Access-Control-Allow-Origin header from the server, if you have control of the server. Otherwise, you can try using JSONP which does not use the XMLHTTPRequest object and is not subject to those same security constraints.

Solution 2:

The host go.com does not allow XSS/CORS from your domain.

XMLHttpRequest cannot load http://go.com/form/front. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://stackoverflow.com' is therefore not allowed access.

Post a Comment for "Sending Ajax Request With A Rest Works But Not With Jquery"