I get a 0 after the result of my ajax requests

WordPress does that by default at the end of admin-ajax.php. It kind of assumes you’ll use one of wp_send_json(), wp_send_json_success(), or wp_send_json_error() to communicate your process’ state (or at least terminate the script yourself). All of those use wp_die() to terminate the script after sending the response. It’s sort of a catch-all response.

Ajax Call in page theme not working?

You shouldn’t be including jQuery explicitly. WP ships with a copy and multiple copies tend to mess things up. See wp_enqueue_script(). You shouldn’t be trying to load PHP file inside a theme directly. It won’t load WordPress environment that way (unless it tries to do so explicitly, which is usually very fragile and pretty much … Read more

Replace link with form to pass variables to javascript / ajax

Worked out the answer with input from non WP-oriented forum and edited above to show. In short the variables were retrieved from WITHIN the js function using getElementByID and prevented error on non-action form with event.preventDefault(); like so: function glitch_player_display() { user_input = document.getElementById(“user_input”).value ? document.getElementById(“user_input”).value : 2; generated_var = document.getElementById(“generated_var”).value ? document.getElementById(“generated_var”).value : “Default_Var”; … Read more

contact form in template with jquery,validate and ajax

WordPress is running Jquery in noconflict mode. (WordPress Codex Reference) or read this brief article I posted some time ago. View it here. You need to replace: $(document).ready(function(){ With this: jQuery(document).ready(function($){ So all together, try this: jQuery(document).ready(function($){ $(“#contact_form”).validate({ rules: { name: “required”, email: { required: true, email: true }, message: “required” }, messages: { name: … Read more

Ajax +wordpress onClick link redirect to new page and create html content

I see two things. You’re missing an action call – you need add_action( ‘wp_ajax_render_admin_charts_page’, ‘render_admin_charts_page’ ); add_action(‘wp_ajax_nopriv_render_admin_charts_page’, ‘render_admin_charts_page’); Plus, from looking at your render_admin_charts_page() you need to change your json dataType to html. Your charts function is outputting html so all you need to do is output it; your alert() should contain all the html … Read more

Manipulate retrieved ajax data in php

Yes you should use die(); in ajax function call, but because you’re not returning data and don’t care what is returned it’s not necessary You should be using nonce, it’s good practice to get used to always using it regardless of the situation. http://codex.wordpress.org/WordPress_Nonces http://codex.wordpress.org/AJAX_in_Plugins You should not be using a function called func, name … Read more

Storing temporary data for a custom post type

If you’re using custom post types, i’d save those date entries as post_meta entries (http://codex.wordpress.org/Function_Reference/add_post_meta). So if your client clicks on a date, you start an ajax request to your plugin/theme file to add or remove a meta entry. you can create one meta_entry named _availability for example and save all dates there (you can … Read more

Using AJAX and PHP to load next post object

The URL you are trying to pass to cannot be used (wp-content/themes/stargazer/populate.php) As @Milo pointed out, please check the AJAX Codex, and it will explain the use of ‘ajaxurl’, which is a protected variable. In short, all AJAX requests must be passed through ‘admin-ajax.php’ whether it is for the frontend or backend.

How to call ajax in plugin file

Use the built-in wordpress Ajax actions: Your jquery will look like this: $(‘#ajax_form’).bind(‘submit’, function() { var form = $(‘#ajax_form’); var data = form.serialize(); data.action = ‘MyPlugin_GetVars’ $.post(‘/wp-admin/admin-ajax.php’, data, function(response) { alert(response); }); return false; Your plugin code something like: add_action(“wp_ajax_MyPlugin_GetVars”, “MyPlugin_GetVars”); add_action(“wp_ajax_nopriv_MyPlugin_GetVars”, “MyPlugin_GetVars”); function MyPlugin_GetVars(){ global $wpdb; // use $wpdb to do your inserting //Do … Read more