Ajax in plugin fails – but only on one blog – no idea why


this seems hard to understand. I created a plugin, and it works fine on different installations of me and a few other blogs.

But on one blog of someone else it fails. After getting through debugs and console entries, I believe I found the source of the failure:

At some step of the process the plugin calls a function with ajax:

jQuery(document).ready(function($) {
            var data = {
               'action': 'mp_throwcontent_2',
               'MedioPay_postid': mp_mypostid,
            'MedioPay_outputs': mp_outputs,
            'MedioPay_number': mp_numberof_payments,
            'MedioPay_userID': mp_userID,
            'Mediopay_newCounter': mp_newCounter,
            'MedioPay_firstPartner': mp_firstPartner,
            'MedioPay_secondPartner': mp_secondPartner,
            'MedioPay_thirdPartner': mp_thirdPartner,
                'MedioPay_fourthPartner': mp_fourthPartner,
                'MedioPay_shareQuote': mp_sharing,
                'MedioPay_preview': mp_preview
        console.log("turning data over");
          jQuery.post(my_ajax_object.ajax_url, data, function(response) {
          console.log("unlock 2 " + response);
              mp_unlockContent2(payment, response);

Then a function is called:

add_action ( 'wp_ajax_nopriv_mp_throwcontent_2', 'mp_throwcontent_2' );

function mp_throwcontent_2() {
   // some ifs and so on 
   // echo "output"

When the plugin starts, Ajax is localized

wp_localize_script( 'ajax-script', 'my_ajax_object',
            array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );

A little quirk: I localized it twice, accidently, here too:

wp_localize_script( 'ajax-script', 'ajax_object',
            array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'we_value' => 1234 ) );

Can this be a problem?

All this works very fine on a few blogs. But in one the operations just stop when the ajax starts. No error, nothing in debug, it just stops.

Does anybody have an idea what I can do to make it run? Is there a fallback to call in case it fails?

Ah, and to make it even weirder: The plugin worked fine on that blog, but suddenly it stopped working, while the owners tells me he didn’t even change anything on his wordpress installation.

, , Christoph Bergmann 12 months 0 Answers 67 views 0

Leave an answer