我需要向php页面发布数据,然后我想获取响应中某个div的文本,但我似乎无法正确地设置它们。我对jQuery不是太熟悉,但通常可以很快弄清楚...我已经尝试了一切,但我认为我只是缺少正确的组合。
$.post("process.php", data , function (response) {
var w = window.open();
$(w.document.body).html(response);
console.log(typeof response); // yeilds string
//create jquery object from the response html
// var $data = $(response); // yeilds Uncaught Error: Syntax error, unrecognized expression: + whole html text
var success = $($.parseHTML(response)).find("#success");
console.log('success');
console.log(success); // see screenshot
console.log(success.text()); // yields nothing
console.log(success.val()); // yields undefined
// if (window.focus) {w.focus()};
},'html');
这是console.log(success);
的输出结果,而红框内的内容则是我想要从响应中获取的...
![这张图片看起来很小...我制作时它并不小。我希望它仍然可读性很强][1]
而这个则会实现那个效果:
var success = $(response).find("#success");
console.log('success');
console.log(success); // yeilds Uncaught Error: Syntax error, unrecognized expression: + whole html text in red
响应是...
<html><head>
<style>
div.totals {
font-family:calibri; font-size:.9em; display:inline-block;
border-width: 2px; border-style: solid; border-color: #FFD324;
background-color: #FAF5D7; color: #514721;
width: 500px;
}
div.error_invalid {
font-family:calibri; font-size:.9em; display:inline-block;
border-width: 2px; border-style: solid; border-color: #9999CC;
background-color: #EEEEFF; color: #7979B8;
}
</style>
</head>
<body>
<div class="totals">Total new rows added: 0 out of 0<br/></div>
<br/><br/>
<div class="totals">Total updated rows: 0 out of 0 <br/></div>
<div id="success">true</div>
</body></html>
我已经尝试过删除样式部分并在 HTML 中添加 head、body 标签,希望它会有所帮助...也就是说,如果响应只包含三个 div,我仍然面临相同的问题。
respone
的内容。 - pktangyue$(w.document.body).find('#success')
? - pktangyue