我创建的是直接从客户端打Salesforce的REST API的AngularJS服务。不过,我一直无法得到它的工作,由于同一产地的限制。即使访问的非认证REST服务,努力当两个$ HTTP,$ http.json和Ajax。我也试过很多JSON,JSONP等。
的组合既然我有这么多的问题,我想,我的一般做法是不正确。也许我需要设置为这个代理服务器?我的后端是火力地堡,所以我现在还没有我自己的服务器。
我不相信Salesforce的API支持CORS,我不能改变这种状况。
下面是我所使用$ HTTP和Ajax尝试的例子。
收益$ http.jsonp('na1.salesforce/services/data/',{标题:{ 内容类型:应用/ JSON的,接受:应用/ JSON}})。 成功(功能(数据,状态,头,配置){ 回调(数据); console.debug(data.json); })。 错误(功能(数据,状态,头,配置){ console.debug(getVersions:无法检索数据:+的eval(数据)); });$阿贾克斯({ 网址:'na15.salesforce/services/data', 键入:GET, 数据类型:JSONP beforeSend:功能(xhrObj){ xhrObj.setRequestHeader(内容类型,应用/ JSON); xhrObj.setRequestHeader(接受,应用/ JSON); xhrObj.setRequestHeader(X-要求,用,XMLHtt prequest); }, 成功:功能(数据){ console.debug(数据); 回调(数据); }, 错误:功能(数据){ } });解决方案
您需要进入Salesforce内再CORS远程设置和白名单域名...
我有同样的问题,它似乎已经解决了这个问题。
看看这有助于here
I've created an AngularJS service that is hitting the Salesforce REST API directly from the client. However, I haven't been able to get it working due to same origin restrictions. Even when accessing non authenticated REST services and trying both $http, $http.json and Ajax. I've also tried lots of combinations of Json, Jsonp etc.
Given that I've had so many issues I'm thinking that my general approach is incorrect. Perhaps I need to setup a proxy server for this? My backend is Firebase so I don't currently have my own server.
I don't believe that the Salesforce API supports CORs and I cannot change that.
Here is an example of what I tried using $http and Ajax.
return $http.jsonp('na1.salesforce/services/data/',{ headers: { 'Content-type': 'application/json', 'Accept': 'application/json' }}). success(function (data, status, headers, config) { callback(data); console.debug(data.json); }). error(function (data, status, headers, config) { console.debug("getVersions: failed to retrieve data: "+eval(data)); }); $.ajax({ url: 'na15.salesforce/services/data', type: "GET", dataType: "jsonp", beforeSend: function(xhrObj){ xhrObj.setRequestHeader("Content-Type","application/json"); xhrObj.setRequestHeader("Accept","application/json"); xhrObj.setRequestHeader("X-Requested-With", "XMLHttpRequest"); }, success: function (data) { console.debug(data); callback(data); }, error: function(data) { } });解决方案
You need to go into Remote Settings within SalesForce then CORS and whitelist the domain name...
I had the same issue and it seemed to have resolved the issue.
See if this helps here
更多推荐
哪些是AngularJS跨域REST调用正确的架构模式?
发布评论