Passing PHP Variables to AJAX Loaded Pages
WP_Query has a $post_count variable. http://codex.wordpress.org/Class_Reference/WP_Query#Properties Just pass that with the script using wp_localize_script
WP_Query has a $post_count variable. http://codex.wordpress.org/Class_Reference/WP_Query#Properties Just pass that with the script using wp_localize_script
You can use like this for send ajax… function my_action_javascript() { ?> <script type=”text/javascript”> jQuery(document).ready(function ($) { var data = { ‘action’: ‘my_action’, ‘whatever’: ‘1’ }; $.post(ajaxurl, data, function (response) { if ($(‘#menu_order’).val() == ” || $(‘#menu_order’).val() == ‘0’) $(‘#menu_order’).val(response); }); }); </script> <?php } add_action(‘admin_footer’, ‘my_action_javascript’); function my_action_callback() { $whatever = intval($_POST[‘whatever’]); //$whatever += … Read more
The issue is with this line: wp_localize_script( ‘ajaxHandle’, ‘myAjax’, array( ‘ajaxurl’ => admin_url( ‘admin_ajax.php’ ) ) ); It should be admin-ajax.php instead of admin_ajax.php.
There isn’t much point to distinguishing admin-ajax.php since it’s essentially same file with same logic running for many many purposes. You are passing action data and hooking into respective action. So action is your identifier. If you are reusing same action and need to further differentiate — just pass more data with your GET/POST request … Read more
FWIW… It APPEARS to have been a misconfiguration in the PHP.INI on a new Development Server (WAMP), which resulted in an unknown corruption of the code upon updating from wp4.0 to 4.1 such that PHP was injecting unwanted white space e.g. “\r\n\r\n…” in my AJAX responses (like a missing closing php ?> tag or someting?) … Read more
The Codex includes a useful page on AJAX in plugins which outlines how to send and receive an ajax request. The code below covers how you would trigger an event when the select field is changed and fire off the ajax request. Make sure you’re getting and setting a nonce value. /** * Only execute … Read more
Maybe you have an image that was smaller or equal to the thumbnail size, if so, then no thumbnail will be created, and this.data[i].sizes.thumbnail will be undefined.
Try using this: $args = array( ‘post_type’ => YOUR_POST_TYPE, ‘meta_query’ => array( array( ‘key’ => ‘_wpcf_belongs_marque-type_id’, ‘value’ => $parent_id ) ) ); In your loop set an else statement just to sure that you query isn’t returning zero results: if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); $output .= ‘<li class=”active-results”>’ . … Read more
Currently I’m assuming that is is backend (front end is slightly different), but it’s very easy to implement on the frontend if required. You are correct in thinking that because you haven’t used the WordPress admin-ajax.php file, all the goodness of WordPress is missing. Fortunately this is easily fixed. Before continuing I recommend that you … Read more
This is a javascript issue. You have to prevent form submission to stop the page from reloading. See event.preventDefault() in jQuery docs. jQuery(“#Submityourskill”).click(function(event){ event.preventDefault(); // the rest of your code });