Javascript 如何从VisualForce页面进行跨域ajax调用
我想从visualforce页面中的脚本进行ajax调用 例如:-Javascript 如何从VisualForce页面进行跨域ajax调用,javascript,ajax,cross-domain,visualforce,Javascript,Ajax,Cross Domain,Visualforce,我想从visualforce页面中的脚本进行ajax调用 例如:- $.ajax({ type : ( typeof method === 'undefined' || method == null) ? 'GET' : method, async : ( typeof IsSync === 'undefined' || IsSync == null) ? false : IsSync, url : url, data : payload, headers : {
$.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未经授权的错误结束。我无法找出这里的问题所在。请对此提供帮助