我想在visualforce页面中通过脚本进行ajax调用。
例如: -
$.ajax({
type : ( typeof method === 'undefined' || method == null) ? 'GET' : method,
async : ( typeof IsSync === 'undefined' || IsSync == null) ? false : IsSync,
url : url,
data : payload,
headers : {
'Content-Type' : 'application/json; charset=UTF-8',
'Authorization' : 'OAuth ' + access_token,
},
success : function(response) {
console.log('inside success ');
callback(response);
},
failure : function(response) {
console.log('inside failure ');
}
});
但此请求以跨域错误结束。 但是当我尝试使用force.com的ajax工具包时: -
sforce.connection.remoteFunction({
type : ( typeof method === 'undefined' || method == null) ? 'GET' : method,
async : ( typeof IsSync === 'undefined' || IsSync == null) ? false : IsSync,
url : url,
data : payload,
headers : {
'Content-Type' : 'application/json; charset=UTF-8',
'Authorization' : 'OAuth ' + access_token,
},
onSuccess : function(response) {
console.log('inside success ');
callback(response);
},
onFailure : function(response) {
console.log('inside failure ');
}
});
但这以401 Unauthorized错误结束。我在这里找不到问题。请帮忙...