Jquery Ajax Push Example - Jquery

How to push ajax response into jquery array?

Snippet Code


  
Rate this page :
  [ 1 votes]

Jquery ajax code push the data received from the ajax and response is pushed into arr array variable.The simple ajax push example code is given below.

<script type='text/javascript'> var arr = []; // ** GLOBAL ** $(document).ready(function() { $.ajax({ type: "POST", url: "ajax-demo.php", data:{admin:"hiox",name:"hscripts"}, success: function (data) { arr.push(data); alert(arr); $('#arrmsg').html(data); }, error: function(error){ alert('Error: ' + error); } }); }); </script> <div id='arrmsg'></div> ajax-demo.php <?php $username = $_POST["name"]; $admin = $_POST["admin"]; if(isset($username)) { echo $admin.",".$username; } ?>

Tags


Ask Questions

Ask Question