Php 为什么我会得到;0“;Wordpress中AJAX调用的响应
我读了很多答案,尝试了很多东西,但我仍然得到了0的回应和问题。我正在尝试创建一个按钮,让我的用户在免费的时候下载文件,但在推特之后,我使用“轻松数字下载”wp插件 我的代码如下:Php 为什么我会得到;0“;Wordpress中AJAX调用的响应,php,jquery,ajax,wordpress,twitter,Php,Jquery,Ajax,Wordpress,Twitter,我读了很多答案,尝试了很多东西,但我仍然得到了0的回应和问题。我正在尝试创建一个按钮,让我的用户在免费的时候下载文件,但在推特之后,我使用“轻松数字下载”wp插件 我的代码如下: add_action( 'wp_enqueue_scripts', 'ritzy_scripts' ); function ritzy_scripts() { wp_enqueue_script( 'custom', get_stylesheet_directory_uri() . '/js/custo
add_action( 'wp_enqueue_scripts', 'ritzy_scripts' );
function ritzy_scripts() {
wp_enqueue_script( 'custom', get_stylesheet_directory_uri() . '/js/custom.js', array( 'jquery' ), CHILD_THEME_VERSION, true );
wp_localize_script( 'custom', 'ritzy', array(
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( $GET['download_id'] ),
)
);
}
/**
* AJAX
*/
add_action('wp_ajax_ritzy', 'ritzy');
add_action('wp_ajax_nopriv_ritzy', 'ritzy');
function ritzy() {
check_ajax_referer( $GET['download_id'], 'nonce' );
// i think may be thats how i can send the link or button
echo edd_get_purchase_link() . '<span id="share_to_download"></span>';
die();
}
响应标题
Cache-Control no-cache, must-revalidate, max-age=0
Connection Keep-Alive
Content-Length 36
Content-Type text/html; charset=UTF-8
Date Wed, 24 Dec 2014 23:05:37 GMT
Expires Wed, 11 Jan 1984 05:00:00 GMT
Keep-Alive timeout=5, max=91
Pragma no-cache
Server Apache/2.4.9 (Win32) OpenSSL/1.0.1g PHP/5.5.11
Set-Cookie edd_items_in_cart=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/wp/
X-Content-Type-Options nosniff
X-Frame-Options SAMEORIGIN
X-Powered-By PHP/5.5.11
X-Robots-Tag noindex
这个反应呢
<span id="share_to_download"></span>
运行此脚本后,HTML将被删除
<span id="tweet-to-download-wrap" data-content="Sparking: A free WordPress theme by @ritzythemes" data-url="http://localhost/wp/themes/sparkling/" data-theme="705">
<span id="share_to_download"></span>
</span>
查看浏览器的开发人员工具。看看JavaScript控制台。它是否报告任何错误?看看网络标签。有人提出要求吗?它得到回应了吗?它们是否包含您期望的数据?在阅读过程中,您是否遇到包含ajax错误处理程序
或如何在控制台中检查请求
?您确实应该尝试缩小问题范围,至少要知道是客户端还是服务器端。您可以提供的所有疑难解答详细信息将有助于添加响应标题,我提供所有信息。因此,状态为200,响应正文中的内容是预期的吗?那么错误处理程序呢?我尝试了警报($('.edd add to cart').length)代码>也看到我得到了什么,看到了零。在运行这个代码之后。我的链接被隐藏或删除,仅显示此HTML。。见上文
<span id="tweet-to-download-wrap" data-content="Sparking: A free WordPress theme by @ritzythemes" data-url="http://localhost/wp/themes/sparkling/" data-theme="705">
<span id="share_to_download"></span>
</span>