jquery & ajax getting data to php in wordpress

Assuming that your script localization and other stuff are set up properly, there is an issue in your back-end script. Your data is in the following format: data : { action : ‘renove_vocabulary’, id_vocabulary : vocabulary, id_user : user } But you are trying to get the data as follows: $id_user = $_POST[‘user_id’]; $id_vacabulary = … Read more

Loading jQuery With Two Fallbacks

I use a similar pattern to enqueue jQuery from the Google CDN (as the CSS Tricks example). However in my footer (typically footer.php) I’ll usually hard code the following fallback. <script type=”text/javascript”> if (typeof jQuery === ‘undefined’) { document.write(‘<script src=”https://wordpress.stackexchange.com/questions/78740/<?php echo get_stylesheet_directory_uri(); ?>/js/jquery.min.js” type=”text/javascript”><\/script>’); } </script> Let me explain what this does and why I … Read more

Extend 3.5 media uploader plugin to change button name

Figured it out using a different method. Help from here. $.fn.oeUpload = function(options) { // Set default options var defaults = { ‘preview’ : ‘.preview-upload’, ‘text’ : ‘.text-upload’, ‘button’ : ‘.button-upload’, ‘name’ : ‘Choose Image’ }; var options = $.extend(defaults, options); var uploader; $(options.button).click(function(e) { e.preventDefault(); //If the uploader object has already been created, reopen … Read more

Modify Custom Field in Media Library using JavaScript

One way to do it (which is probably evil) is to select the control by adding a block of javascript using the tr field of $form_fields: function set_image_data( $form_fields, $post ) { $form_fields[‘text_color’] = array( ‘label’ => ‘Text Color’, ‘input’ => ‘text’, ‘value’ => get_post_meta( $post->ID, ‘_text_color’, true ) ); ob_start(); ?> <script type=”text/javascript”> jQuery(‘[name$=”[text_color]”]’).myColorPicker(); … Read more

How to pass both action and formdata in wordpress ajax?

try to add the action in the formdata : var formData=new FormData(document.getElementById(‘landlordregform’)); formData.append(“action”, “custom_landlord_registration_process”); jQuery.ajax({ url: jQuery(“#cusajaxurl”).val(), type: ‘POST’, data: formData, cache: false, processData: false, contentType: false, success: function(data) { console.log(data); } });

How to link WordPress heartbeat to ajax form

Saving data Based on Heartbeat API, you can add custom data to the sent heartbeat on heartbeat-send event in js. This would be used instead of the ajax function you have in your code example. jQuery( document ).on( ‘heartbeat-send’, function ( event, data ) { // Grab the required form data data.location = jQuery(‘input[name=”location”]:checked’).val(); data.userid … Read more

problem with ajax and the path to the php page

To use the WordPress ajax url you can pass the var using wp_localize_script: wp_enqueue_script( ‘functions’, get_bloginfo( ‘stylesheet_directory’ ) . ‘/js/functions.js’, array( ‘jquery’ ), false); wp_localize_script( ‘functions’, ‘MyAjax’, array( ‘ajaxurl’ => admin_url( ‘admin-ajax.php’ ) ) ); In your functions.js $.ajax({ type: “POST”, url: MyAjax.ajaxurl, data: {p:alt_p}, success: function(data) { alert(data); } });