Home Web Front-end JS Tutorial About the simple call to get JSON data in JS (the code is attached, simple and crude)

About the simple call to get JSON data in JS (the code is attached, simple and crude)

May 18, 2018 am 10:49 AM
javascript json Obtain

The following is what I have compiled for you about simple calls to obtain JSON data in JS. Interested students can take a look.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
<html>  
  <head>  
    <title>异步调用JSON</title>  
  </head>  
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
  <script type="text/javascript">  
  <!--  
   var xmlhttp;  
    // 创建XMLHTTPRequest对象  
    function createXMLHTTPRequest()  
    {  
         if(window.ActiveXObject)//②如果当前浏览器为IE  
         {  
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");  
         }  
         else if(window.XMLHttpRequest)//③如果是其他浏览器  
         {  
            xmlhttp = new XMLHttpRequest();  
         }else  
         {  
             alert("Your browser does not support XMLHTTP.");  
        }  
    }  
    function getInfo()  
    {  
      createXMLHTTPRequest();  
      xmlhttp.open("get", "http://audicms.ogilvy.com.cn/webapp/front/dealerapi!getdealerlist.action", true);  
      xmlhttp.onreadystatechange = returnInfo;  
      xmlhttp.send(null);  
    }  
    function returnInfo()  
    {  
      if(xmlhttp.readyState == 4)  
      {  
       var info = xmlhttp.responseText;  
       eval("var json= " + info);  
       var message="";  
       var dealerlocation="";  
       var salesphone="";  
      for(var i=0;i<json.dealers.length;i++){  
           message+="经销商名称:<font style=&#39;color:red;&#39;>" + json.dealers[i].name + "</font>  <br/>";  
           salesphone+="经销商电话:<font style=&#39;color:red;&#39;>" + json.dealers[i].salesphone + "</font>  <br/>";  
           dealerlocation+="经销商经纬度:<font style=&#39;color:red;&#39;>" + json.dealers[i].location + "</font>  <br/>";  
      }  
       document.getElementById("showInfo").innerHTML = message;  
       document.getElementById("salesphone").innerHTML = salesphone  
       document.getElementById("location").innerHTML=dealerlocation;  
      }  
    }  
  -->  
  </script>  
  <body>  
  <br/><br/>  
  <h2 style="color: red;">异步调用JSON</h2>  
  <br/><input type="button" value="获取JSON数据" onclick="getInfo()" />  
   <table>  
    <tr>  
    <td><div id="showInfo"></div></td>  
    <td><span id="salesphone"><span></td>  
    <td><span id="location"><span></td>  
    </tr>  
   </table>  
  </body>  
</html>
Copy after login

The above is a simple call I compiled for you to get JSON data in JS. I hope it will be helpful to you in the future.

Related articles:

Entry-level video.js usage notes (code attached)

Talk about native JS and Other JS differences

In regards to adding ! in front of function in js, the code is attached

The above is the detailed content of About the simple call to get JSON data in JS (the code is attached, simple and crude). For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1662
14
PHP Tutorial
1261
29
C# Tutorial
1234
24
Where to get Google security code Where to get Google security code Mar 30, 2024 am 11:11 AM

Google Authenticator is a tool used to protect the security of user accounts, and its key is important information used to generate dynamic verification codes. If you forget the key of Google Authenticator and can only verify it through the security code, then the editor of this website will bring you a detailed introduction on where to get the Google security code. I hope it can help you. If you want to know more Users please continue reading below! First open the phone settings and enter the settings page. Scroll down the page and find Google. Go to the Google page and click on Google Account. Enter the account page and click View under the verification code. Enter your password or use your fingerprint to verify your identity. Obtain a Google security code and use the security code to verify your Google identity.

Performance optimization tips for converting PHP arrays to JSON Performance optimization tips for converting PHP arrays to JSON May 04, 2024 pm 06:15 PM

Performance optimization methods for converting PHP arrays to JSON include: using JSON extensions and the json_encode() function; adding the JSON_UNESCAPED_UNICODE option to avoid character escaping; using buffers to improve loop encoding performance; caching JSON encoding results; and considering using a third-party JSON encoding library.

How do annotations in the Jackson library control JSON serialization and deserialization? How do annotations in the Jackson library control JSON serialization and deserialization? May 06, 2024 pm 10:09 PM

Annotations in the Jackson library control JSON serialization and deserialization: Serialization: @JsonIgnore: Ignore the property @JsonProperty: Specify the name @JsonGetter: Use the get method @JsonSetter: Use the set method Deserialization: @JsonIgnoreProperties: Ignore the property @ JsonProperty: Specify name @JsonCreator: Use constructor @JsonDeserialize: Custom logic

How to install dual SIM on Realme 12 Pro? How to install dual SIM on Realme 12 Pro? Mar 18, 2024 pm 02:10 PM

Although the general operations of domestic mobile phones are very similar, there are still some differences in some details. For example, different mobile phone models and manufacturers may have different dual-SIM installation methods. Erzhenwo 12Pro, a new mobile phone, also supports dual-SIM dual standby, but how should dual-SIM be installed on this phone? How to install dual SIM on Realme 12Pro? Remember to turn off your phone before installation. Step 1: Find the SIM card tray: Find the SIM card tray of the phone. Usually, in the Realme 12 Pro, the SIM card tray is located on the side or top of the phone. Step 2: Insert the first SIM card. Use a dedicated SIM card pin or a small object to insert it into the slot in the SIM card tray. Then, carefully insert the first SIM card.

How to use PHP functions to process JSON data? How to use PHP functions to process JSON data? May 04, 2024 pm 03:21 PM

PHP provides the following functions to process JSON data: Parse JSON data: Use json_decode() to convert a JSON string into a PHP array. Create JSON data: Use json_encode() to convert a PHP array or object into a JSON string. Get specific values ​​of JSON data: Use PHP array functions to access specific values, such as key-value pairs or array elements.

Quick tips for converting PHP arrays to JSON Quick tips for converting PHP arrays to JSON May 03, 2024 pm 06:33 PM

PHP arrays can be converted to JSON strings through the json_encode() function (for example: $json=json_encode($array);), and conversely, the json_decode() function can be used to convert from JSON to arrays ($array=json_decode($json);) . Other tips include avoiding deep conversions, specifying custom options, and using third-party libraries.

How to get fake future crystal coins How to get fake future crystal coins Mar 22, 2024 am 08:00 AM

Many players want to know how to obtain fake future crystal coins. There are actually four different methods, including purchasing gift packages, completing tasks, producing goods, developing land, etc. Players can choose different ways to earn crystal coins according to their needs. The specific content is as follows: Get up and take a look at this guide on how to obtain fake future crystal coins. Fake Future Guide: How to get Fake Future Crystal Coins 1. Purchase the gift package mall to purchase the crystal coin gift package. 2. Obtained by completing tasks and completing main and side tasks. 3. Produce goods. Produce goods in your home to obtain crystal coins. 4. Developing land can also be obtained by developing land, but the reward is one-time.

How to save JSON data to database in Golang? How to save JSON data to database in Golang? Jun 06, 2024 am 11:24 AM

JSON data can be saved into a MySQL database by using the gjson library or the json.Unmarshal function. The gjson library provides convenience methods to parse JSON fields, and the json.Unmarshal function requires a target type pointer to unmarshal JSON data. Both methods require preparing SQL statements and performing insert operations to persist the data into the database.

See all articles