我需要将数据发布到 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,我也会遇到同样的问题。