Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/236.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 深入到iframe_Php_Jquery_Xml - Fatal编程技术网

Php 深入到iframe

Php 深入到iframe,php,jquery,xml,Php,Jquery,Xml,我有一个非常复杂的东西,它深入到iframe中,从XML结果中检索属性。(我这样做是为了避免从这个非现场服务器获取数据所涉及的其他10亿个问题。) $(文档).ready(函数(){ $('.frame')。每个(函数(){ var mls=$(this.attr('mls'), usda=$(this.contents().find('Property').attr('quality'); $(“#测试”)。追加(mls+''+usda+'); }); }); iFrame中的数据如下所示

我有一个非常复杂的东西,它深入到iframe中,从XML结果中检索属性。(我这样做是为了避免从这个非现场服务器获取数据所涉及的其他10亿个问题。)


$(文档).ready(函数(){
$('.frame')。每个(函数(){
var mls=$(this.attr('mls'),
usda=$(this.contents().find('Property').attr('quality');
$(“#测试”)。追加(mls+''+usda+'
); }); });
iFrame中的数据如下所示

<?xml version="1.0" encoding="UTF-8"?>
<Eligibility xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <Adjusted AnnualIncome="" TotalDeduction="" AdjustedIncome="" ElderlyDeduction="" YoungDeduction="">
        </Adjusted>
        <Section502Guaranted MaximumAdjusted="" Eligible="">
        </Section502Guaranted>
        <Section502Direct MaximumAdjusted="" Eligible="">
        </Section502Direct>
        <Property Eligibility="InEligible" MapURL="http://rdgdwe.sc.egov.usda.gov/eligibilitymaps/index.jsp?app=RBSIELG&amp;ADDRESS=7865 ILLINOIS CASEYVILLE&amp;STATE=IL&amp;ZIP=62232" />
        <ErrorResponse EngineId="" HostName="" MaxSeverity="" LogFile="" Class="" Module="" Severity="" Time="">
                <Message Code="" Type="" Text="" />
        </ErrorResponse>
</Eligibility>

我需要
属性
节点中的
合格性
属性。。。
更新抱歉,过早点击发送。我现在得到的
$(this).contents().find('Property').attr('qualification')
的结果只是“未定义”。

您需要使用JS以正确的方式访问iframe并使用XML DOM:

var f = $('.frame')[0];
var Property = f.contentDocument.getElementsByTagName('Property')[0];
var Eligibility = Property.getAttribute('Eligibility');
或者类似的。注意:这只有在域、端口和协议匹配时才可能!(指业主文件和iframe文件。)

编辑啊,我现在看到iframe的URL很可能与您的网站不同。否则这就行不通了。Javascript(浏览器)不允许跨站点脚本。出于非常好的安全原因

您需要使用PHP读取XML。更容易:

$xml = simplexml_load_file($url); // requires allow_url_fopen to be on
$Eligibility = (string)$xml->Property['Eligibility'];

(没有测试过。)

避免使用iframe,大多数iframe元素都不推荐使用。@Jonast92您想详细说明一下吗?不推荐使用的iframe元素?Iframes非常活跃,而且会持续很长时间。关于Iframes:align:HTML5不支持。HTML 4.01中已弃用,frameborder:在HTML5中不受支持,longdesc:在HTML5中不受支持,marginheight:在HTML5中不受支持,marginwidth:在HTML5中不受支持,scrolling:在HTML5中不受支持。加上我在过去几年里从那些在这一领域工作了很长时间的人那里得到的提示,他们基本上说这已经过时了,但也许我错了。你对@Rudie?关于w3schools有什么看法?iframe URL域将始终与我的当前域不同。那么你是说iframe的内容必须与试图访问它的js脚本位于同一台服务器上?我试着使用cURL,但它太痛苦了,不能达到我想要的效果。如何使用PHP读取iframe XML?它没有任何作用。我在
$xml
$quality
上尝试了
print\r
echo
,但什么也没有显示。如您所述,allow\u url\u fopen设置为on。该url不是实际文件,而是从该url返回的。这是否需要区别对待?
print\r($xml)
没有显示任何内容??真奇怪。它应该显示一些“XML”,或者在某处抛出通知或警告。请尝试
var\u dump($xml)
。如果
$url
是有效的url,PHP将自动下载文档,simplexml将对其进行解析。“PHP将自动下载文档”部分要求
allow\u url\u fopen
$xml = simplexml_load_file($url); // requires allow_url_fopen to be on
$Eligibility = (string)$xml->Property['Eligibility'];