dp0518 2013-04-11 21:03
浏览 40

jQuery AJAX没有在插件中执行

I asked this over at the Wordpress side of Stackexchange, but ran out of answers that led me anywhere, so was hoping someone here could help. Sorry if this cross-post breaks a rule. The original was here. https://wordpress.stackexchange.com/questions/95075/jquery-ajax-call-not-executing-in-plugin

I've been working on a class for my free plugins that outputs a "Donate" form. The "No thanks" dismissal link hides the form and runs an AJAX call to update a WP Option keeping track of the dismissal.

I'm having issues getting the called PHP function to actually fire. I added the "success" function to output an echo that I added to the PHP function called by the AJAX (typically, the function has no output, only a WP Option update), but "data" is always 0 and nothing happens in the database.

I have several other AJAX calls in this plugin, all of which work, but this is the only one that is inside of a class. Earlier in development of the class, it worked, but I can't figure out what I could've done to break it. I've even tried stripping it down to just a declaration of the AJAX registration and a function that outputs a test message with no success.

I'm guessing that WP isn't actually able to use the function for some reason.

Here's the pertinent part of my jQuery AJAX call

    // Create the AJAX data
    ajax_call_data = {
            'action': 'dismiss_ppd_dmgr',
            'nonce': $nonce
    };

    // Call the AJAX function to update the options
    jQuery.ajax({
            url: ajaxurl,
            type: 'post',
            data: ajax_call_data,
            success: function(data) { alert( data ) }
     });

In the class, I have an attribute ajax_call, which is set at class instantiation and I'm adding my call to Wordpress like so. I've verified that $this->ajax_call is populated properly and also tried hardcoding it, instead of using the variable.

    add_action( 'wp_ajax_' . $this->ajax_call , array( &$this , 'dismiss_form' ) );

$this->ajax_call outputs the "dismiss_ppd_dmgr". I've echoed wp_filter and found wp_ajax_dismiss_ppd_dmgr registered pointing to dismiss_form() in my class. But the result is always 0 and nothing is updated in the database.

Things I've tried:

  • with and without &
  • hard-coded instead of with $this->ajax_call
  • calling the add_action directly in the constructor as well as putting it inside of a function that's called by an admin_init action
  • creating the AJAX add_action outside of the class as

     add_action( 'wp_ajax_dismiss_ppd_dmgr' , array( $ppd_dmgr , 'dismiss_form' ) );
    

Does anyone have any ideas as to why WP doesn't like my AJAX call?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 python的qt5界面
    • ¥15 无线电能传输系统MATLAB仿真问题
    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100