Hot answers tagged

2

Now I got it! WordPress is just awesome. Also Thank you knif3r, your suggestions help me lot. I am trying to explain it in my words. Please correct me, if I am wrong. What is nonce? Nonce is something like security hash to prevent attacks and mistakes. It creates unique identifiers to check if the ajax request is coming from website or not. In WordPress ...


2

You cannot use wp_localize_script in page template. You have to use it in functions.php or your custom plugin, after you register your script, which is usually in the wp_enqueue_scripts action. https://codex.wordpress.org/Function_Reference/wp_localize_script


2

How can i return a PHP value from a WordPress page to a JQuery function? Use wp_localize_script to create an object and pass it to the JavaScript.


1

Simply, you can not redirect the user from the sever in a Ajax callback. The redirect in the Ajax callback redirecta the Ajax request itself, it doesn't redirect the user to a new location. I hope you understand what I mean. Remember that Ajax, by definition, is asynchronous. So, you need to think in another workflow. For example (just an example, the ...


1

See documentation here but don't miss the note 2 and the following points : AJAX on the front-end is more complicated, ajaxurl is not defined so you have to call it with wp_localize_script(). you have to use wp_ajax_nopriv_{action} for non logged in users there could be security issue !!! About the third point : Be careful because you give access to ...


1

A simple answer to your question is that you have the data type as JSON in your ajax request and you are passing a string in it. You need to pass a json object in the ajax request when you chose dataType equals to JSON. A JSON object is typically a key pair value inside curly braces. Here is a reference where you can see how ajax requests can be implemented ...


1

The following is the solution I came up with: <div id="selection1"> <div id="dropdown1"> <form id="choice1" action="<?php bloginfo('url'); ?>" method="get"> <?php $select = wp_dropdown_pages( array( 'post_type' => 'page', '...


1

For the sake of documentation. I spent two days working out an ajax problem and this afternoon when I started testing, my PHP ajax handler wasn't getting called.... Extraordinarily frustrating. The solution to my problem (which might help others) is the priority of the add_action callback: add_action( "wp_ajax_{$my_handler}", array('class_name', '...



Only top voted, non community-wiki answers of a minimum length are eligible