Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
121
rated 0 times [  127] [ 6]  / answers: 1 / hits: 18168  / 10 Years ago, wed, november 5, 2014, 12:00:00

I want to solve my AJAX cross domain problem. This is the error message I receive in Chrome:




XMLHttpRequest cannot load http://'myaddress'/TEST/user/login/testuserid . Request header field Access-Control-Allow-Origin is not allowed by Access-Control-Allow-Headers.




this is my source code



$.ajax({
crossDomain : true,
dataType : json,
url: fullUrl,
method: method,
headers:headers,
data: body,
success: function(data, state, res){
if (data == null)
data = '';

console.log( '[[[[[[[[SUCCESS!!]]]]]]] url: ' + url + ', state:' + state + ', data : ' + JSON.stringify( data ) );
callback(data, state, res);
},
error: function(data, state){
if ( data == null )
data = '';

console.log( '[[[[[[[[[ERROR!!]]]]]]]]] url: ' + url + ', s tate:' + state + ', data : ' + JSON.stringify( data ) );
callback(data, state, null);
}
});


Servlet code for cross Domain



httpRes.setHeader(Access-Control-Allow-Origin, *);
httpRes.setHeader(Access-Control-Allow-Methods, GET,PUT,POST,DELETE);
httpRes.setHeader(Access-Control-Allow-Headers, *);

More From » jquery

 Answers
11

You need to use JSONP to make CROSS DOMAIN Requests.



Please read:



Loading cross domain endpoint with jQuery AJAX



Make cross-domain ajax JSONP request with jQuery


[#68910] Sunday, November 2, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
darrylm

Total Points: 499
Total Questions: 131
Total Answers: 108

Location: Saudi Arabia
Member since Mon, Sep 5, 2022
2 Years ago
;