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);
}
Blockquote ですので、皆さんの助けを借りて上記のコードを取得しました。上記のコードは txtbox に文字列を入力しますが、文字列の各要素にアクセスできません。文字列は、Jsone_encode を使用して PHP ファイルからページングされた配列です。
配列はこのようなものです。[{"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 テーブルから取得され、大きい