我正在尝试使用此代码对我的crm api进行ajax调用,但无法正常工作:
var username = 'admin';
var password = '1';
$.ajax
({
type: "GET",
dataType: 'json',
async: false,
url: "http://demo.espocrm.com/basic/api/v1/App/user",
headers: {
"Authorization": "Basic " + btoa(username + ":" + password)
}
})
.done(function(){
alert('Authenticated!')
})
.fail(function(){
alert('Error!')
});
来电从www.domain.com
到crm.domain.com
.htaccess
crm.domain.com
上的我有以下代码:
<ifModule mod_headers.c>
Header set Access-Control-Allow-Origin "http://www.domain.com"
Header set Access-Control-Allow-Methods "OPTIONS, GET, PUT, POST, DELETE, HEAD"
Header set Access-Control-Max-Age "1800"
</ifModule>
jsnot
并使用此网址:http://demo.espocrm.com/basic/api/v1/App/user?callback=?
错误是:
OPTIONS http://crm.domain.com/api/v1/App/user?_=1437237158381 500 (Internal Server Error)
XMLHttpRequest cannot load http://crm.domain.com/api/v1/App/user?_=1437237158381. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://www.domain.com' is therefore not allowed access. The response had HTTP status code 500.
当我使用jsnop
时:
GET http://crm.domain.com/api/v1/App/user?callback=jQuery21404605716757941991_1437238651212&_=1437238651213