Select content from JQuery ajax return object

前端 未结 3 1009
自闭症患者
自闭症患者 2021-01-27 13:40

As I understand it, the JQuery load() function retrieves a document and can perform the quivelent of:

$(\'#somecontenttograb\').html()

upon it.

3条回答
  •  感动是毒
    2021-01-27 14:27

    If the web page in question lives on a different server, you won't be able to use any AJAX to get access to the returned html due to issues with the same origin policy. The only type of data that you will be able to get via AJAX from another server is JSONP. This uses a script tag to load the data and operate with it using a javascript callback. The other way to handle another site is to have your server proxy the request, i.e., you call a method on your server which, in turn, performs the actual request for you.

    If you are accessing the same server, then I'd suggest setting up some server methods to return just the HTML that you want to inject on the page rather than loading and parsing an entire page to get just some elements.

提交回复
热议问题