function ajaxFunction(){
var ajaxRequest; // The variable that enables the use of Ajax technology!
try{
// Compatible with Opera 8.0+, Firefox, and Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// For Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser is too old for this script!");
return false;
}
}
}
// Define a function to handle data received from the server
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
$.post('userfind.php', function(data) {
$("#resultTXT").val(data);
var response = data;
var parsedJSON = eval('('+response+')');
alert('parsedJSON:'+parsedJSON);
var result=parsedJSON.result;
var count=parsedJSON.count;
alert('result:'+result+' count:'+count);
},'json'
); }
}
ajaxRequest.open("POST", "userfind.php", true);
ajaxRequest.send(null);
}
Blockquote With your assistance, I have successfully implemented the code above that populates a text box with a string received from a PHP file using Json_encode. However, I am facing difficulties in accessing individual elements within the string, which is an array.
The structure of the array is as follows:
[{"user_id":"2790","freelancer_name":"","order_id":"9121","orderamount":"0.00"
My goal is to write a code snippet like this:
document.getElementById("_proId").value = user_id;
document.getElementById("_buyerSt").value = freelancer_name;
document.getElementById("_buyerDesc").value = order_id;
document.getElementById("_mngSt").value = orderamount;
... etc
Blockquote My issue lies in how to parse the string and extract the data contained within. Specifically, these two variables:
var result=parsedJSON.result;
var count=parsedJSON.count;
alert (""+result);
alert (""+count);
Only return 'undefined' when alerted.
I kindly seek assistance in extracting the data from the string, as the array retrieved from a MySQL table is extensive.