Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I would like to be able to use the jQuery Fancybox's Ajax feature to request datas from the front-end. Here is a part of the code i'm using on the plugin part :

wp_localize_script( 'wpPluginjs', 'ajax_vars', array(
           'url' => admin_url( 'admin-ajax.php' ),
           'nonce' => wp_create_nonce( 'ajax-nonce' )
        )
);

And on the js part :

var url = ajax_vars.url;
var nonce = ajax_vars.nonce;

$( "#list" ).fancybox({
    maxWidth    : 800,
    maxHeight   : 600,
    openEffect  : 'none',
    closeEffect : 'none',
    title       : false,
    type: 'ajax',
    href: ajax_vars.url+'&nonce='+ajax_vars.nonce
});

But i actually keep having the following error when i click "#list" :

"NetworkError: 404 Not Found - http://mywebsite.com/wp-admin/admin-ajax.php&nonce=7bbd764db8"

I tried with a basic jQuery Ajax request and it worked like a charm. It seems that there is a problem with Fancybox, it's still unable to find the correct "admin-ajax.php" url.

I also unsuccessfully tried to add wp_localize_script() to the wp_enqueue_script() function that loads jQuery Fancybox.

Any help would be greatly appreciated.

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

&nonce should be ?nonce. The ? begins a query string, the & separates arguments within a query string.

share|improve this answer
    
Yep was a mistake, sorry, my mind was probably on another part of the code in that moment... –  Arrakeen Apr 26 '13 at 14:50
add comment

I don't know if it's the best practice but if i use the following href it works:

href: '../wp-admin/admin-ajax.php?nonce='+ajax_var.nonce
share|improve this answer
    
Note the difference between what you've written into that URL and what you have above. In your non-working version: &nonce, in the version that works: ?nonce. –  Milo Apr 26 '13 at 14:36
    
You are right, i didn't even notice that part of the code... –  Arrakeen Apr 26 '13 at 14:49
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.