Javascript 如何从jquery.post响应中获取div属性?
我在服务器上设置了两个文档,“index.php”和“proc.php”。在“index.php”中,我编写了一些JavaScript代码,将向“proc.php”发送post请求。php以div的形式发送成功响应:Javascript 如何从jquery.post响应中获取div属性?,javascript,jquery,attr,.post,Javascript,Jquery,Attr,.post,我在服务器上设置了两个文档,“index.php”和“proc.php”。在“index.php”中,我编写了一些JavaScript代码,将向“proc.php”发送post请求。php以div的形式发送成功响应: <div id="serverResponseDiv" data-class="new-class"> The request was successful, and this is the response. </div> 如何从服务器响应div
<div id="serverResponseDiv" data-class="new-class">
The request was successful, and this is the response.
</div>
如何从服务器响应div获取属性值?我在谷歌上做了多次搜索,但都找不到我问题的答案。请提供帮助。您不应将“数据”功能用作属性
尝试其他方法,如类或自定义属性
如果您做不到,请尝试以下方法:
var nClass = $('#serverResponseDiv[data-class="newClass"]');
你有没有试着检查你收到的
数据
?你的页面上肯定没有第二个id为的元素(serverResponseDiv),因为这会解释一些事情…@JacqueGoupil我需要做什么来检查数据字符串,并从中获取属性值?我的意思是使用调试器(chrome的开发工具工作得很好)然后在那里放置一个断点,或者只在“data”变量中添加console.log(),以查看其中的确切内容
var nClass = $('#serverResponseDiv[data-class="newClass"]');