jQuery:将页面主体加载到变量中 [英] jQuery: Load body of page into variable

查看:74
本文介绍了jQuery:将页面主体加载到变量中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用jQuery将PHP脚本的结果加载到变量中。该脚本被传递给用户使用GET请求输入的内容。我只想将脚本吐出到< body> 标记中。以下是我尝试过的:

JS: $ b

  function loader(){
var typed = $('#i')。val(); (获得用户输入的
$ .get(script.php,{i:typed},function(loaded){dataloaded = loaded;});
alert($(dataloaded).find('body'))
}



<但它只显示 [Objec object] 。我怎样才能获得一个有用的值,这只是加载页面正文的内容?



我知道PHP的作品,我只需要JS。
脚本 echo 类似于 1 !! 2 (两个数字用两个感叹号分隔)。



谢谢! 改变了我试图抓取到XML的页面。我使用 $。find 从XML页面单独获取每个感兴趣的元素,这非常适合这个特定的应用程序。



这个问题已经消失,因为不再有一个 head 部分要忽略,我只是抓住了单个的XML元素。



感谢您的宝贵时间和帮助!


I'm using jQuery to load the result of a PHP script into a variable. The script is passed something that the user typed with a GET request. I want to take just what the script spit out into its <body> tag. Here's what I've tried:

JS:

function loader() {
    var typed = $('#i').val(); //get what user typed in
    $.get("script.php", {i: typed}, function(loaded) {dataloaded = loaded;});
    alert($(dataloaded).find('body'))
}

But it just displays [Objec object]. How can I get a useful value that is just the contents of the body of a loaded page?

I know the PHP works, I just need the JS.
The script echos something like 1!!2 (two numbers separated by two exclamation points).

Thanks!

解决方案

I changed the page that I'm trying to fetch to XML. I'm using $.find to get each element of interest individually from the XML page, which suits this particular app well.

This problem has disappeared, as there is no longer a head section to ignore, and I'm just grabbing individual XML elements anyway.

Thanks for all your time and help!

这篇关于jQuery:将页面主体加载到变量中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆