哪些是AngularJS跨域REST调用正确的架构模式?

编程入门 行业动态 更新时间:2024-10-11 03:15:48
本文介绍了哪些是AngularJS跨域REST调用正确的架构模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我创建的是直接从客户端打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调用正确的架构模式?

本文发布于:2023-11-28 12:46:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1642459.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:架构   正确   模式   AngularJS   跨域

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!