wordpress Ajax success doesn’t return the value

You can try this… …rather than returning the value, send a JSON success message. $response = new WP_REST_Response($final_price_return, 200); wp_send_json_success( $response ); wp_die(); //you have to end the process, so if you’re getting just a 0 returned in your JS success, it’s because of this. Then, in your JS/jQuery: success: function (success, data) { var … Read more

WordPress wp_localize_script nonce and ajax URL

wp_localize_script() doesn’t care much which script handle you use as long as it is a valid one. You could use your theme’s or Elementor’s main script handle with the function to make the data available for your script. You’ll need to check your theme’s or Elementors source coude to find what these handles are. Side … Read more

Can admin-ajax.php be used for spam purposes? And if yes, how to prevent that?

This is why you use nonces. $.ajax({ type: “POST”, url: ‘/wp-admin/admin-ajax.php’, data: { action: ‘mail_function’, message: ‘test’, _nonce: <?php echo wp_create_nonce( ‘mail_function_’ . $post->ID ) ?>}, dataType: “html”, success: function(data) { } }); Then in your PHP function: function my_ajax_mailer() { if ( ! wp_verify_nonce( $_REQUEST[‘_nonce’], ‘mail_function_’ . $post->ID ) ) return; // send mail… … Read more

Widget won’t work due to old JavaScript? Any ideas how to make it work? [closed]

From your site i can say that script is not being loaded because of wrong opening quote for script tag.Use ” instead of ” So <script src=”http://lookbook.nu/widget/profile.js?id=2303472&width=standard&align=left&stats_fans=1&fanbox=yes&hash=14575a9cd02fd36d2758e5db3cb92b5a”></script> Should be this <script src=”http://lookbook.nu/widget/profile.js?id=2303472&width=standard&align=left&stats_fans=1&fanbox=yes&hash=14575a9cd02fd36d2758e5db3cb92b5a”></script> Update: Add <script> $LB = jQuery; </script> before the other script tag. I mean before <script src=”http://lookbook.nu/widget/profile.js?id=2303472&width=standard&align=left&stats_fans=1&fanbox=yes&hash=14575a9cd02fd36d2758e5db3cb92b5a”></script>

ajax for visitors wordpress

You also need to add your action callback to non-privileged users. It works the same way as you registered your my_action_callback – you just need to add another line. add_action( ‘wp_ajax_my_action’, ‘my_action_callback’ ); add_action( ‘wp_ajax_nopriv_my_action’, ‘my_action_callback’ ); Notice the wp_ajax_nopriv_ in front of your action – this tells WordPress that any user may call this … Read more

wordpress ajax always return 0

In function myajax_submit send the headers before echoing any content header(‘Content-Type: application/json’); echo json_encode($response); die();

Detecting IP Address of someone using ‘copy’ function [closed]

Here is a road map to do this. You should adjust this code to your exact requirements: You can detect copy event in JavaScript using this code in your page <script> jQuery(document).ready( function($) { function myFunction() { // here make an ajax call to send data to server $.ajax({ url: “http://yourwebsite.com”, type: ‘POST’, data: {‘copied’: … Read more

How can I json_encode the output of my function?

Not sure if the get_all_images() function is the one that is added to your wp_ajax_{action} hook. If it is you will want to output a string back to your js. I would define a variable and concatenate the img html to it as you loop through your images. function get_all_images() { //your code $response=””; foreach($images … Read more