我正在解决同事在将表单发布到 API 的页面上留下的错误,并在 iframe 中接收 XML 响应,然后使用 XML 解析子项。该页面适用于 IE9、Chrome 和 Firefox,但不适用于 IE 8。
表格:
<form action="../../includes/functions/ADapi.php" method="POST" target="response" id="addForm" >
<fields galore></fields galore>
</form
<iframe name="response" id="response" style="display:none;" ></iframe>
响应:
<?xml version="1.0" encoding="utf-8" ?>
- <xmlresponse>
<DateTime>2012-04-26 15:36:47</DateTime>
<confirmationcode>success</confirmationcode>
</xmlresponse>
的JavaScript:
function getResponse()
{
var myIFrame = document.getElementById("response");
var content = myIFrame.contentWindow.document.getElementsByTagName('confirmationcode');
var insertID = myIFrame.contentWindow.document.getElementsByTagName('id');
//var sql = myIFrame.contentWindow.document.getElementsByTagName('SQL');
var response = $(content).text();
var responseID = $(insertID).text();
//alert($(sql).text());
if(response == "Success" || response == 'success')
{
if(mode == 'edit')
{
post_to_url("/edit-contact", {type: 'edit', cust: id, mod: 'update',field : '<?php if(isset($_POST['field'])){ echo $_POST['field']; }?>',operator : '<?php if(isset($_POST['operator'])){ echo $_POST['operator']; }?>',criteria : '<?php if(isset($_POST['criteria'])){ echo $_POST['criteria']; }?>'});
}
else
{
post_to_url("/edit-contact", {type: 'edit', cust: responseID, mod: 'insert',field : '<?php if(isset($_POST['field'])){ echo $_POST['field']; }?>',operator : '<?php if(isset($_POST['operator'])){ echo $_POST['operator']; }?>',criteria : '<?php if(isset($_POST['criteria'])){ echo $_POST['criteria']; }?>'});
}
}
else
{
alert("Error!");
}
}
每次运行时,它都会弹出“错误!”的警报
任何帮助将不胜感激。