Ajax responseText Parsing json Data Case
- 2021-11-13 00:43:30
- OfStack
Solution ajax processing server side returns the result responseText is JSON data.
First, the contents of the file in json format are as follows:
{
"city":"ShangHai",
"telephone":"123456789"
}
Second, the json data returned by the server is the above content. In responseText, there are two methods to fetch it out now:
Method 1:
var json=JSON.parse(request.responseText);
alert(json.city);
Method 2:
var result = request.responseText;
var jsonObject=eval("("+result+")");
alert(jsonObject.telephone);