function ajaxFunction(){
var ajaxRequest; // The variable that makes Ajax possible!
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// 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 to run me!");
return false;
}
}
}
// Create a function that will receive data sent 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);
}
塊引用 所以我得到了我上面的代碼,你的球員的幫助。上面的代碼會用字符串填充txtbox,但我無法訪問字符串的每個元素。該字符串是使用Jsone_encode從PHP文件中分頁的數組。使用eval解析JSON字符串
該數組是這樣的。 [{"user_id":"2790","freelancer_name":"","order_id":"9121","orderamount":"0.00"
我想做的事就是寫一個這樣的代碼:
document.getElementById("_proId").value = user_id;
document.getElementById("_buyerSt").value = freelancer_name;
document.getElementById("_buyerDesc").value = order_id;
document.getElementById("_mngSt").value = orderamount;
... etc
塊引用 所以我的問題是如何分割字符串,並獲取數據。這2瓦爾
var result=parsedJSON.result;
var count=parsedJSON.count;
alert (""+result);
alert (""+count);
只是提醒我不確定。
請幫我從字符串中獲取數據。
數組是從一個MySQL表提取和它的大
爲什麼不使用JSON.parse()? – Bergi 2012-07-12 01:40:17