How do I pass a 2D array from JavaScript into PHP -


i working on school project involves extracting product data multiple online retailers using various apis/ajax calls, , sorting data in php (i use 1 ajax call each retailer). snippet of code working on shown below. cannot figure out how

  1. push temporary array containing product attributes ("average", "price", "name", "url", , "image") each product master array (array of arrays) ,

  2. post master array php in such way can index values in sorting purposes.

function get_results() {   $(document).ready(function() {     var master_array = [];     $.ajax({       type: "get",       url: "http//:www.source1.com",       datatype: "xml",       success: function(xml) {         $(xml).find('product').each(function() {           var average = $(this).find('average').text();           var price = $(this).find('price').text();           var name = $(this).find('name').text();           var url = $(this).find('url').text();           var image = $(this).find('image').text();           master_array.push([average, price, name, url, image]);         });       }     });     $.ajax({       type: "get",       url: "http//:www.source2.com",       datatype: "xml",       success: function(xml) {         $(xml).find('product').each(function() {           var average = $(this).find('average').text();           var price = $(this).find('price').text();           var name = $(this).find('name').text();           var url = $(this).find('url').text();           var image = $(this).find('image').text();           master_array.push([average, price, name, url, image]);         });       }     });   }); } 

you should see example code jquery ajax function: http://api.jquery.com/jquery.ajax/. here example code:

$.ajax({   method: "post",   url: "some.php",   data: { name: "john", location: "boston" } }) .done(function( msg ) {     alert( "data saved: " + msg ); }); 

your updated function can this:

function get_results() {   $(document).ready(function() {     var master_array = [];     $(xml).find('product').each(function() {         var average = $(this).find('average').text();         var price = $(this).find('price').text();         var name = $(this).find('name').text();         var url = $(this).find('url').text();         var image = $(this).find('image').text();         master_array.push([average, price, name, url, image]);     });     $.ajax({       type: "post",       url: "http//:www.source1.com",       data: master_array,       success: function(response) {         alert('data posted');       },      fail: function(response) {         alert('data not posted');       }     });    }); } 

in above code success , fail functions called when servers returns response. if response correctly sent success function called. if there error on server fail function called.


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -