$. Ajax requests Baidu api (aggregate data),. ajaxapi

Source: Internet
Author: User

$. Ajax requests Baidu api (aggregate data),. ajaxapi

A friend interviewed me some time ago and called the api using JQuery's ajax method. I will briefly introduce JQuery's Ajax and use Baidu API Store's open API for actual call practices ,!!! Currently, Baidu api has changed to the charging mode, so this demonstration uses aggregate data for demonstration. Beginners can refer to it and then use the template engine to render the page.

 

 <script>
$.ajax({ url:'http://apis.juhe.cn/idcard/index', type:'get', data:{ cardno:'420116199201203716', dtype:'json', key:'44d1cbaa1665151ec1514e685b68a764' }, dataType:'jsonp', success:function(info){ console.log(info) }, error:function(error,Msgerror){ console.log(Msgerror) } }) </script>

 

Parameters: <-- all are based on api requirements -->

1. url: Request Parameters (default current page)

2. type: Request Method ()

3. data: data sent to the server using an Object or String parameter. If it is no longer a string, it is automatically converted to the string format.

Cardno, dtype, and key are required parameters.

 

4. dataType: Data Type returned by the expected Server

 

5. success: the callback function called after the request is successful

 

6. The function called when the request fails. This function has three parameters: XMLHttpRequest object, error message, and captured error object (optional)

The return value of a successful request. You only need to use the rendering engine to render the page. The first time I wrote a podcast, I was a bit trembling and not detailed. Later I will write more podcasts, summarize the language, and improve my understanding of the technology. I also hope that this will allow you to deepen your understanding of the knowledge and make wonderful comments. Thank you for reading this article.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.