zoukankan      html  css  js  c++  java
  • AngularJs(Part 6)

    Overcomming same-origin policy restrictions with JSONP.
    AJAX has a restriction that it can only retrieve data from the same resource.
    There are several techniques for accessing dta exposed by external servers:JSONP and CORS.

    AngularJS contains API that uses JSONP to get data from foreign server.
        $http.jsonp(url,config);
    the url must contain the JSON_CALLBACK request parameter. that is the URL must be like
    xxxx?callback=JSON_CALLBACK

    Check out CORS, another way to overcome same-origin policy restrictions
    CORS is a W3C specification that aims at solving the same problem as JSONP does , only in a
    more standard,reliable , and secure way.
    The CORS specificatoin builds on top of the XMLHttpRequest object ot enable the cross-domain AJAX
    requests.
    CORS requests are roughly divided into "simple" and "non-simple" ones. GET ,POST,HEAD requests
    are considered as "simple".
    With non-simple requests , the browser is oblisged to send a probing OPTIONS request and wait for the
    server's approval before issuing the primary request. So the server must be well-configured for handling
    the OPTIONS request.


    But, there is also another way to approach the cross-domain request. that is use a local server as
    a proxy to a foreign one.  
    for example, back-end is written by JAVA. then i can get foreign data through JAVA, and then send it
    to font-end when requested.

  • 相关阅读:
    第一次做的破网页
    c++初学指针
    eskibana
    有关JSON以及JSON在PHP中的应用
    比较全的log4j 配置
    验证码类
    PHP 兼容 Curl/Socket/Stream 的 HTTP 操作类
    PHP缓存技术
    Fatal error: Call to undefined function curl_init()解决方案
    socket基础
  • 原文地址:https://www.cnblogs.com/formyjava/p/4166310.html
Copyright © 2011-2022 走看看