1
$result = mysql_query ("SELECT * FROM order_list");

$test = array();
$i=0;

$myjsons = array();
while($row = mysql_fetch_assoc($result)){ 
    echo $myjsons[] = json_encode(array($row));
}

およびAJAXjavascript

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) {
            document.getElementById("resultTXT").value = eval("    (" + ajaxRequest.responseText + ")");
        }
    }
    ajaxRequest.open("POST", "userfind.php", true);
    ajaxRequest.send(null);
}​

javascript関数は配列をテキストボックスに保存しません

誰かがここで何が問題なのか教えてもらえますか?

ありがとう

4

2 に答える 2

1

この例では、JSON出力は無効になります。配列を作成し、次のように単一のjsonエンコード配列を出力します。

$myjsons = array();
while($row = mysql_fetch_assoc($result)){ 
    $myjsons[] = $row;
}
echo json_encode($myjsons);
于 2012-07-10T13:14:37.583 に答える
1

試す:

 while($row = mysql_fetch_assoc($result)){ 
     $myjsons[] = json_encode(array($row));
    }
 echo json_encode($myjsons);

それ以外の

while($row = mysql_fetch_assoc($result)){ 
  echo $myjsons[] = json_encode(array($row));
}

ajax 呼び出しに jquery ライブラリを使用できます http://api.jquery.com/jQuery.post/

$.post('userfind.php', function(data) {
   $("#resultTXT").val(data);// ==document.getElementById("resultTXT").value =data;
},'json'

);
于 2012-07-10T13:18:27.647 に答える