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

Summary of Linux Logical Volume Management (LVM) usage

Managing disk space is an important daily task fo...

Understanding render in Vue scaffolding

In the vue scaffolding, we can see that in the ne...

Detailed steps to install JDK and Tomcat in Linux environment

Table of contents 1. Install JDK Manual Installat...

Do you know how many connections a Linux server can handle?

Preface First, let's see how to identify a TC...

Nginx configuration file detailed explanation and optimization suggestions guide

Table of contents 1. Overview 2. nginx.conf 1) Co...

Related commands to completely uninstall nginx under ubuntu16.04

nginx Overview nginx is a free, open source, high...

Modify the jvm encoding problem when Tomcat is running

question: Recently, garbled data appeared when de...

Analysis of Vue element background authentication process

Preface: Recently, I encountered a management sys...

Notes on Using Textarea

Why mention textarea specifically? Because the tex...

Ubuntu 20.04 Best Configuration Guide (Newbie Essential)

1. System Configuration 1. Turn off sudo password...

Basic principles for compiling a website homepage

1. The organizational structure of the hypertext d...

Solution for Docker container not recognizing fonts such as Songti

Problem background: When using docker to deploy t...

Docker installation and deployment example on Linux

After reading the following article, you can depl...