I am using jQuery, JavaScript and PHP. My Ajax.php file just displays the data. File test.php has assigns the value to a JavaScript function.
My problem is I am not able to get the values that are assigned by test.php, from getList(data).
Is anything wrong with my logic? What do I do to get the values assigned by test.php to get displayed in the getList() function?
$.ajax({ type: 'POST', url: 'ajax.php', data: 'id=' + id , success: function(data){ $('#response').html(data); if(flag != 0){ flag = 0; $.get('test.php', function(data){ alert('Data Loaded: ' + data); getList(data); }); } } //Success }); //Ajax
And test.php has the following.
<?php print '<script language='javascript'>'; print ' temp[temp.length]=new Array('STA-VES','East',4500);'; print ' temp[temp.length]=new Array('STA-CRF','West',5400);'; print '</script>'; ?>
My JavaScript function has:
var temp=new Array(); getList(){ alert(temp.length); for(var i=0; i<temp.length; i++){ var val = temp[i]; } }
The below code will output the values you require into JSON that when reconstructed will resemble your array:
Then your jQuery code can parse the response back into a JavaScript object.