2010-11-25 38 views
0

我正在开发一个WordPress的补丁。这个jQuery代码在wordpress中出现问题

这是XML是什么

<?xml version='1.0' standalone='yes'?><wp_ajax><response action='autosave_1'><wp_error id='1' position='1'><response_data><![CDATA[<p> 
<h1>Error establishing a database connection</h1> 
<p>This either means that the username and password information in your <code>wp-config.php</code> file is incorrect or we can't contact the database server at <code>localhost</code>. This could mean your host's database server is down.</p> 
<ul> 
    <li>Are you sure you have the correct username and password?</li> 
    <li>Are you sure that you have typed the correct hostname?</li> 
    <li>Are you sure that the database server is running?</li> 
</ul> 
<p>If you're unsure what these terms mean you should probably contact your host. If you still need help you can always visit the <a href='http://wordpress.org/support/'>WordPress Support Forums</a>.</p> 
</p>]]></response_data><supplemental></supplemental></wp_error></response></wp_ajax> 

和解析上述XML脚本:wp-ajax-response.dev.js

的问题是:jQuery('wp_error', child).each().size()总是即使它有<wp_error>标签上面的XML返回零。

为什么会发生这种情况?

回答

0

也许你应该试试这个,而不是jQuery('wp_error', child).each(function(){return this.size()});。如果它仍然返回零,那么问题出在选择器上,在这种情况下,没有wp_error元素包含child,所以您应该检查更多关于child所指的位置(它指向哪个DOM的哪个部分)。