How do I POST an array of objects with $.ajax (jQuery or Zepto)

Be sure to stringify before sending. I leaned on the libraries too much and thought they would encode properly based on the contentType I was posting, but they do not seem to. Works: $.ajax({ url: _saveAllDevicesUrl , type: ‘POST’ , contentType: ‘application/json’ , data: JSON.stringify(postData) //stringify is important , success: _madeSave.bind(this) }); I prefer this … Read more

How to return an array from an AJAX call?

Use JSON to transfer data types (arrays and objects) between client and server. In PHP: json_encode json_decode In JavaScript: JSON.stringify JSON.parse PHP: echo json_encode($id_numbers); JavaScript: id_numbers = JSON.parse(msg); As Wolfgang mentioned, you can give a fourth parameter to jQuery to automatically decode JSON for you. id_numbers = new Array(); $.ajax({ url:”Example.php”, type:”POST”, success:function(msg){ id_numbers = … Read more

How to Set Selected value in Multi-Value Select in Jquery-Select2.?

Well actually your only need $.each to get all values, it will help you jsfiddle.net/NdQbw/5 <div class=”divright”> <select id=”drp_Books_Ill_Illustrations” class=”leaderMultiSelctdropdown Books_Illustrations” name=”drp_Books_Ill_Illustrations” multiple=””> <option value=” “>No illustrations</option> <option value=”a” selected>Illustrations</option> <option value=”b”>Maps</option> <option value=”c” selected>selectedPortraits</option> </select> </div> <div class=”divright”> <select id=”drp_Books_Ill_Illustrations1″ class=” Books_Illustrations” name=”drp_Books_Ill_Illustrations” multiple=””> <option value=” “>No illustrations</option> <option value=”a”>Illustrations</option> <option value=”b”>Maps</option> <option value=”c”>selectedPortraits</option> … Read more

‘append’ called on an object that does not implement interface FormData

in order to use formdata with jquery you have to set the correct options $.ajax({ url : “/function/pro_pic_upload.php”, type: “POST”, data : postData, processData: false, contentType: false, success:function(data, textStatus, jqXHR){ $(“#pro_pix img”).last().show(); $(“#pro_pix img”).first().hide(); $(“#pro_pix h6”).text(data); }, error: function(jqXHR, textStatus, errorThrown){ //if fails } }); .ajax reference processData (default: true) Type: Boolean By default, data … Read more

Get data from html and and pass the data back to the front end using ajax or js

You can use ajax with Jquery. You can see this doc for more details. How to proceed: Configure js scripts In your HTML file template: Load Jquery: Load Jquery preferably before any other javascript files. Either statically: <script type=text/javascript src=”https://stackoverflow.com/questions/52870184/{{url_for(“static’, filename=”jquery.js”) }}”> </script> Or using Google’s AJAX Libraries API: <script src=”https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js”></script> <script>window.jQuery || document.write(‘<script src=”https://stackoverflow.com/questions/52870184/{{url_for(“static’, … Read more

Hook AJAX in WordPress

First of all you need to add hooks in proper way // For the users that are not logged in add_action( ‘wp_ajax_nopriv_addItemAJAX’, ‘addItemAJAX_callback’ ); // For the users that are logged in: add_action( ‘wp_ajax_addItemAJAX’, ‘addItemAJAX_callback’ ); // ajax handler function addItemAJAX_callback() { // code goes here // since $debugArray is an array, so die(json_encode($debugArray)); // … Read more