Tag Info

New answers tagged

0

You can't use 2 echos for an ajax response. Try this: js: $atj.post(MyAjax.ajaxurl, requestData).done(function(result){ console.log(result); if(result == 'success'){ $atj('.training-form [type=text]').val(''); $atj('.training-form-message').append('<p class="training-form-complete-message">Thank you for the ...


0

You would save the Ajax response to the database. Here are a few tutorials that might be helpful: Tutorial on Using Ajax in Wordpress Plugins How to Use Ajax for Data Insertion in WordPress How to Insert Data into Database using Ajax


-1

<script type="text/javascript"> var a = <?php echo $a=1; ?> // OR var a = <?php global $a; echo $a; ?> </script> We can directly use PHP variable in javascript as i showed in example If your php code and javascript code in same page then you can use first approach. Else your php code in different page and included it in current ...


1

You could try to use the .children method to filter through your response - let's say the posts are comming in containers with a particular selector on them - say, you add class="mypost" on the divs when you build the response -, then you can do something like this in your success method: // ... ...


0

I got it. I just should have used $_REQUEST instead of $_POST within every function which handles AJAX requests.


0

I simply had to remove 'is_page() && ' in both the if and the elseif function the_ajax_breadcrumb($post_id) { ob_start(); $args = array('page_id' => $post_id); $the_query = new WP_Query($args); $currentBefore = '<li><a>'; $currentAfter = '</a></li>'; while ( $the_query->have_posts() ) { ...


1

An ajax request happens in completely separate load, it will have no awareness about which page you are making request from and will have no main query or query conditionals. If you want to retrieve something based on the context of page you are making request from then you need to pass that information in your ajax request and retrieve posts based on it.


0

Indeed, you forgot to mention the destination of the request, and you are also missing ajaxurl (since you are using wp_ajax). Another, more simple solution would be to create a php file to handle the request (ex: process-request.php), then to specify the url of this file in the ajax object before you submit your request. This solution is less "WordPress ...


1

From quick look at your code you seem to be omitting where you are submitting request to. By default it is just current page, which isn't typically equipped to receive the request. Since you are using wp_ajax_ hook you need to point request at admin-ajax.php endpoint. On admin side the URL is provided in ajaxurl JS variable, on front end side you would need ...


0

For posterity. You can still use $.ajax() without having to use $.ajaxSeteup(). All you need to specify is the type and make sure it is set to POST. $.ajax({ url: localized_script.ajax_url, /* Admin ajax url from localized script */ type: 'POST', /* Important */ data: data_object, /* Data object including 'action' and all post variables */ ...


-2

'suppress_filters' => true This work for me!


0

How about using a simple css solution hiding the <li>s you don't want to show at first or using jQuery to calculate the number of <li>s to show or hide prev/next set?


0

There are some "magic" request parameters that are better avoided, mostly anything that can be used as a parameter name at a request url but also some more like "email" (don't think it is well documented and a quick google failed to bring a good reference). Try to change the names of your parameters especially the "author" and "cat", maybe just add some ...


1

I solved it instead of using return ( $result == true ? 'success' : 'error' ); use echo ( $result == true ? 'success' : 'error' );


1

If you want your code to look good you should properly format it first. Aside from that you are able to combine your AJAX (or to be exact your jQuery/javascript) into one block. Actually you should put it in a separate javascript file, but you can read all about that on the AJAX in Plugins on the Codex page (from where you got your code anyway) or in the WP ...


0

Update ... Here's the Final Code That Worked for Me This may not be perfect, but it seems to be working well for me with no errors. Feel free to add any suggestions for improvement if you have any. JS Code jQuery(document).ready(function($) { var count = 2; jQuery("#la-chooser").change(function() { loadArticlebyCat(this.value); }); ...


0

You are using esc_attr(), which isn't available if you use define( 'SHORTINIT', true ); , see source. So you either have to load the formatting.php manually or have to ditch the define( 'SHORTINIT', true ); - actually like the example in the thread you are referring to shows. As said in the comment, I checked out mentally after the first function that ...


0

Your syntax for passing the settings array is incorrect and also you have not specified the name for the textarea in the settings array which is why it returns you an empty alert. Syntax from WordPress Codex: wp_editor( $content, $editor_id, $settings = array() ); $content (string) (required) - Initial content for the editor $editor_id (string) ...


4

For non-admin users to be able to use an ajax function, you need to also include a second hook using wp_ajax_nopriv So right after this: add_action('wp_ajax_add_category_bookly', 'add_category_bookly_callback'); you should include this: add_action('wp_ajax_nopriv_add_category_bookly', 'add_category_bookly_callback');


0

If I understand correctly you need the original form to display the values of what has just been posted. You also need the table to display 0 on values that haven't been calculated. At the moment the table calculates information perfectly with a submit refreshing the page. You can use the if(isset($_POST["fieldname"])){ variable you have above to do ...


0

Well, my code seems to be ok. I just needed to remove the "disabled" state of the field that prevented the update metadata for a completely unknown reason to me. Merci Sim ;) Replaced this <input type="text" id="union_id_field" name="union_id_field" value="<?php echo esc_attr( $value ); ?>" disabled> By this <input type="text" ...


-2

if you wnat to redirect then use javascript window.lcation="your url" in your php code try this in your function that call by the ajaxcall add_action('wp_ajax_nopriv_custom_register', 'custom_register'); add_action('wp_ajax_custom_register', 'custom_register'); function custom_register(){ //process $url=home_url(); ?> < script> ...


1

ajaxSubmit isn't a core jQuery function. It seems that you have to either include a jQuery Plugin (like this), or rewrite your function to use a syntax like this one, using jQuery post() $.post(ajaxurl, data, function(response) { // responsefunction } or with the jQuery ajax() $.ajax({ url: ajaxurl, context: data }); Be sure that you have ...


0

Thanks for all the help, unfortunately I don't have enough time to figure out what isn't working (customer tapping feet). All suggestions did'nt work, so I'm going the "normal" (ugly) way of reading out $_POST. Thanks for the efford.


0

I think that main problem here is that you try to use "fail" to indicate the state where form has errors. This is wrong, because ajax call will "success" even when form will have errors, because from jquery point of view - it made a ajax call and got response. Fail will be called only on 404 errors etc.


0

Another possible fix is to add: $is_ajax = true; at line 11 in an override version of review-order.php, which should be copied from: wp-contents/plugins/woocommerce/template/checkout/ to: wp-contents/themes/{YOUR_THEME}/woocommerce/checkout/


0

Change your wp_localize_script-Call to the right Action: wp_localize_script( 'addItemToNav', 'menuItems', array( // URL to wp-admin/admin-ajax.php to process the request 'ajaxurl' => admin_url( 'admin-ajax.php' ), // generate a nonce with a unique ID "myajax-post-comment-nonce" 'postCommentNonce' => wp_create_nonce( ...


0

Your AJAX Requests requires an JSON to be returned. But I think your function doesn't return valid JSON. Haven't tested it, but this function should work: function update_nav_items() { // Testing stuff $response = json_encode( array( 'response' => 'success', 'html' => 'some value' ) ); // first JSON encode ob_clean(); ...


1

It is a bad idea IMO to have one request that behave differently depending if the are executed from page A or page B. Think of AJAX as a formal API and treat it like that and your life will be easier in the long run. If you need two different behaviors on the front end and backend then just use two different requests.


1

Ajax request in Wordpress is always performed in admin side, so is_admin() returns always true. If you need to know where the ajax request come from you need to check where the script is executed, not where the script send the ajax request. For example: add_action('wp_enqueue_scripts', 'cyb_enqueue_scripts'); function cyb_enqueue_scripts() { ...


0

Solution: Add wp_editor() in somewhere that works perfectly and hide it. <div class="hidden-editor-container" style="display:none;"> <?php wp_editor( '', 'editor' ); ?> </div> after that assign editor contents to the global JS variable. EDITOR = $('.hidden-editor-container').contents(); Finally when the ajax page is loaded append ...



Top 50 recent answers are included