angular.js - angularjs get、post、jsonp怎么实现跨域请求?请求数据错误的问题
PHPz
PHPz 2017-05-15 17:01:56
0
2
713

使用get、post

使用jsonp


在URL加callback也并不能解决问题、
我看了几种方法都是通过服务器端设置,有没有不用同过服务端的方法实现?

PHPz
PHPz

学习是最好的投资!

reply all (2)
阿神

Cross-domain requests are like going to someone else's house to play. If they don't open the door for you, how can you enter their house. Just let the server set up a whitelist and specify those domain names that can be accessed by requests. La. You can also set the backend to accept requests under any domain name during the testing phase, and then turn off this setting after it is officially launched, but this method is not recommended.

    仅有的幸福

    First,jsonp只能用于getdata.

    Usejsonp跨域获取数据的一个大前提是后端返回的数据得是一段可执行的Javascriptscript, take your code above as an example, the returned content should look like this:

    Request Code

    $http.jsonp('http://192.168.3.248:9000/system/user?callback=parseResponse');

    Return data

    parseResponse({ "dataList": [ { "email": "1646123897@qq.com", "enable": 0, "id": "123094" ...}... ] })

    Otherwise I will report your mistake:Uncaught SyntaxError: Unexpected token :

    Regarding cross-domain, you should first understand what the problem is, and then build public APIs and CORS after reading this

      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!