0

だから私は一日中これを試しましたが、解決できないようです.PHPスクリプトからJSON文字列を取得するAJAXがいくつかありますが、今はそれをJavaScriptに入れたいと思っています.

私が試したのはこれです:

var xmlhttp;
xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function()
{
    if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    var obj = jQuery.parseJSON(xmlhttp.responseText);

    }
}
xmlhttp.open("GET","back.php?q="+query,true);
xmlhttp.send();

しかし、私が得るのは

Uncaught SyntaxError: Unexpected token < x.extend.parseJSON xmlhttp.onreadystatechange

次のようなすべてのタイプのコードを試しました

obj = JSON.parse(xmlhttp.responseText);
alert(obj.length);

私が何をしても、基本的に上記のエラーが発生します..何をすべきかわからない..私は本当にこれをjQuery/JSで解決したい..

助けてくれてありがとう!

4

2 に答える 2

1

jquery を使用すると、次のことができます。

$.ajax({
    url: "back.php?q="+query,
    dataType: "json",
    success: function(response) {
        alert(response.length);
    }
});
于 2013-09-19T20:15:20.510 に答える
0

単純に...

url='your/url/to/the/file.php';
$.getJSON(url,
        function(data){
          alert(data);
          });
        });
于 2013-09-19T20:17:42.310 に答える