Retrieve html across domains using jQuery and JSONP

后端 未结 2 747
遥遥无期
遥遥无期 2021-01-03 11:22

I have a form that outputs one simple line of html A LINK

I can access the process directly with data appended to the u

相关标签:
2条回答
  • 2021-01-03 11:43

    JSONP doesn't work like this, you're not sending JSON at all, you're sending HTML.

    JSONP is strictly a GET request (made by creating a <script> tag), you cannot POST cross-domain and get the result back...it just doesn't work that way. The way JSONP works is it basically adds this to your page:

    <script type="text/javascript" src="http://site.com/form.asp?order=something&callback=myFunc"></script>
    

    ....that response has to be valid JavaScript, typically it looks like:

    myFunc({ "key": "value"...data, etc... });
    

    It doesn't work for fetching HTML, it just throws a syntax error, this limitation is very intentional, and part of the security blocks in place (part of the same origin policy).

    0 讨论(0)
  • 2021-01-03 11:54

    You can still post/get cross domain on the client:

    flyJSONP/YQL
    jankyPOST/postMessage/contentWindow
    CORS

    0 讨论(0)
提交回复
热议问题