Get value from other page

跟風遠走 提交于 2021-01-28 21:27:30

问题


I got a site where I want to pick up a value and save it in my script, but the value is inside a div on a different page. I have tried so many different things by now, and I cant get it to work.

Do anyone have a idea ?

Thanks!


回答1:


if you are sure you have the cross-origin allowed , then just use load , and retreive that specific div

$( "#result" ).load( "ajax/test.html #container" );

where result is the div you want to store data inside , and container is the div on the other page.

will also save time and traffic to load the whole page using get.

http://api.jquery.com/load/




回答2:


Try this:

 $.get("pageurl",function(data){
      $("yourdiv").html(data);
 });

OR Better

jQuery.ajax({
    url: "YourPageURL",
    success: function(result) {
        var html = jQuery('<div>').html(result); // Instead of div tag you can use specific id with div

    },
});


来源:https://stackoverflow.com/questions/20314937/get-value-from-other-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!