Home > Web Front-end > JS Tutorial > body text

Operation steps for using getJSON() to asynchronously request the server to return json data

php中世界最好的语言
Release: 2018-03-31 15:32:39
Original
1311 people have browsed it

This time I will bring you the steps of using getJSON() to asynchronously request the server to return json data. What are the precautions for using getJSON() to asynchronously request the server to return json data. The following is a practical case. , let’s take a look. We can use jquery's getJSON() method to request the server to return json format data:

js code:

function test(){
    $.getJSON("JsonServlet",function(result){
      alert(result.name);
    });
  }
Copy after login

Server-side servlet response:

@Override
  protected void doPost(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
    String person="{\"name\":\"zhangsan\",\"sex\":\"man\",\"age\":\"23\"}";
    resp.getWriter().print(person);
  }
Copy after login

Note: Both json data attribute names and character values ​​are required It’s double quotation marks I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website!

Recommended reading:

How to use ajax to submit comments and automatically refresh them


How to use ajax to pass an array to the background

The above is the detailed content of Operation steps for using getJSON() to asynchronously request the server to return json data. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template