Ajax responseText parses json data case study

Ajax responseText parses json data case study

Solve the problem that the responseText returned by the server after ajax processing 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. Now we need to get it out. There are two ways:

Method 1:

var json = JSON.parse(request.responseText);  

alert(json.city);

Method 2:

var result = request.responseText;  

var jsonObject = eval("("+result+")");  

alert(jsonObject.telephone);

This is the end of this article about the detailed case of Ajax responseText parsing json data. For more related Ajax responseText parsing json data content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • The responseText in Ajax returns a page instead of a value
  • How to solve the problem of garbled responseText of ajax
  • JSON, AJAX, Maven Basics
  • Ajax login verification implementation code
  • Ajax realizes the linkage between provinces, cities and districts
  • Preliminary implementation of Ajax (using vscode+node.js+express framework)

<<:  Detailed explanation of the installation and configuration process of mysql8.018 on linux

>>:  Nginx prohibits direct access via IP and redirects to a custom 500 page

Recommend

js returns to the previous page and refreshes the code

1. Javascript returns to the previous page history...

Two ways to write stored procedures in Mysql with and without return values

Process 1: with return value: drop procedure if e...

Linux completely removes node.js and reinstalls it through the yum command

first step Delete it once with the built-in packa...

Method and introduction of table index definition in MySQL

Overview An index is a table of correspondence be...

Introduction to Linux common hard disk management commands

Table of contents 1. df command 2. du command 3. ...

The difference between this.$router and this.$route in Vue and the push() method

The official document states: By injecting the ro...

How to use CURRENT_TIMESTAMP in MySQL

Table of contents Use of CURRENT_TIMESTAMP timest...

Best Practices Guide for Storing Dates in MySQL

Table of contents Preface Do not use strings to s...

How to mount a data disk on Tencent Cloud Server Centos

First, check whether the hard disk device has a d...

Mysql sorting to get ranking example code

The code looks like this: SELECT @i:=@i+1 rowNum,...

MySQL learning to create and operate databases and table DDL for beginners

Table of contents 1. Operate the database 1.1 Cre...

Table td picture horizontally and vertically centered code

Html code: Copy code The code is as follows: <t...

The difference between useEffect and useLayoutEffect in React

Table of contents Prerequisites useEffect commitB...