As the title says, I am trying to access (POST) by calling jQuery AJAX to the web url, http://host:port/... or http://localhost:8080/... from a local HTML file, c:\home.html . I can not make it work.
I did Google and also saw some questions here, but I can't get it to work. I need help here. Here is what I have tried so far.
- dataType: jsonp
- crossDomain: true
- Setting the title in my answer:
response.setHeader("Access-Control-Allow-Origin", "*");
None of the three browsers work - IE, FF or Chrome. The request never reaches the server. Here are some of the errors that I see.
- No transport (IE) unless jsonp is used.
- NS_BINDING_ABORTED / Error loading content (NS_ERROR_DOCUMENT_NOT_CACHED) to FF
This is my code. I would be grateful for any help. I am using jquery-1.8.2.min.js .
var http_host = "http://localhost:8080"; function su (pc, p) { var suUrl = http_host + "/ps/api/v2/authorize.json"; $.ajax({ type: 'POST', url: suUrl, data: { phone_cell: pc, password: p, }, dataType: "json", crossDomain: true, success: osu, error: oe }); return false; } function osu (d) { console.log(d); } function oe(xhr, ts, et) { alert("ServerError: " + et); }
An example would be a perfect pointer.
jquery ajax cors cross-domain
user977505
source share