Possible Duplicate:
Overcoming Cross-Domain issues 开发者_运维百科
Is it possible to make a cross-domain $.ajax setRequestHeader ?
I´m trying to do this:
$.ajax({
url: 'http://remote_url_here',
type: 'GET',
dataType: 'json',
beforeSend: function(xhr) {
xhr.setRequestHeader('Authorization', 'TRUEREST username=xxxx&password=yyyy');
},
success: function() { alert('Sucess')},
error: function() { alert('Error'); },
});
And in my "remote_url" im doing a $_SERVER['HTTP_AUTHORIZATION']
but its allways empty. I also tried looking in firebug but no headers are set, same thing if type:POST.
Am i doing something wrong?
Thanks in advance!
If you control http://remote_url_here you can via the Access-Control-Allow-Origin header
https://developer.mozilla.org/en/HTTP_access_control
header('Access-Control-Allow-Origin: *');
or
header('Access-Control-Allow-Origin: http://permitted_domain.com');
add crossDomain:true
to your $.ajax()
params
You can't do a cross-domain ajax request due to javascript's same-origin policy, unless you use JSONP (which isn't useful in your case, I think).
Hope this helps. Cheers
UPDATE Now you can with the crossDomain: true
option.
精彩评论