Use JSONP to load an html page

后端 未结 6 778
不思量自难忘°
不思量自难忘° 2020-11-27 17:13

I\'m trying to load an external page using JSONP, but the page is an HTML page, I just want to grab the contents of it using ajax.

EDIT: T

6条回答
  •  攒了一身酷
    2020-11-27 17:35

    http://en.wikipedia.org/wiki/JSONP#Script_element_injection

    Making a JSONP call (in other words, to employ this usage pattern), requires a script element. Therefore, for each new JSONP request, the browser must add (or reuse) a new element—in other words, inject the element—into the HTML DOM, with the desired value for the "src" attribute. This element is then evaluated, the src URL is retrieved, and the response JSON is evaluated.

    Now look at your error:

    Uncaught SyntaxError: Unexpected token <

    < is the first character of any html tag, probably this is the start of , in this case, which is, of course, invalid JavaScript.

    And NO, you can't use JSONP for fetching html data.

提交回复
热议问题