2010-11-25 48 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的哪個部分)。