Difference: 1. The core of ajax is to obtain non-this page content through xmlHttpRequest, while the core of jsonp is to dynamically add script tags to call the js script provided by the server; 2. jsonp only supports get requests, while ajax supports get and post requests.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
The calling methods of ajax and jsonp are very similar. The purpose is to request the URL and then process the data returned by the server. Therefore, frameworks such as jquery and ext encapsulate jsonp as a form of ajax. . Let's take a look at jsonp and ajax and introduce their differences.
1. Working principle of Ajax
It is equivalent to adding an intermediate layer (AJAX engine) between the user and the server, so that the user Operations and server responses are asynchronous. The Ajax engine will do some data verification and data processing for user requests. Not all requests are submitted to the server. When new data needs to be read from the server, the Ajax engine submits the request to the server on its behalf. The biggest advantage of AJAX is that it communicates with the server to maintain data without refreshing the entire page.
Process:
The first step: Create an ajax engine object, IE6 is new ActiveXObject, other browsers are new xmlHttpRequest object;
The second step: Call The open method starts a request for sending. The open method passes in three parameters: request type, request url and a Boolean value;
The third step: call the send method to send;
The fourth step Step: Process the callback function onreadystatechange, process the response data when readState = 4 (response data completed), and status = 200 (request successful).
Note: The callback function must be written before open() and send().
2. Working principle of Jsonp
Dynamicly create a script tag and use the script tag's src attribute to achieve cross-domain access without restrictions.
The web client calls the js format file (suffix .json) dynamically generated on the cross-domain server in the same way as calling the script. The purpose of the json file dynamically generated by the server is to load the data required by the client. .
Allows the user to pass a callback parameter to the server, and then when the server returns data, it will use this callback parameter as a function name to wrap the json data, so that the client can customize its own function to automatically process the return. data.
3. The difference between Ajax and jsonp
-
The core of ajax is to obtain non-this page content through xmlHttpRequest;
The core of jsonp is to dynamically add script tags to call the js script (suffix .json) provided by the server.
jsonp is a method or non-mandatory protocol, and ajax does not necessarily have to use json format to transmit data.
jsonp only supports get requests, and ajax supports get and post requests.
【Related tutorial recommendations: AJAX video tutorial】
The above is the detailed content of What is the difference between jsonp and ajax. For more information, please follow other related articles on the PHP Chinese website!

Scrapy是一个开源的Python爬虫框架,它可以快速高效地从网站上获取数据。然而,很多网站采用了Ajax异步加载技术,使得Scrapy无法直接获取数据。本文将介绍基于Ajax异步加载的Scrapy实现方法。一、Ajax异步加载原理Ajax异步加载:在传统的页面加载方式中,浏览器发送请求到服务器后,必须等待服务器返回响应并将页面全部加载完毕才能进行下一步操

作为一种基于MVC模式的PHP框架,CakePHP已成为许多Web开发人员的首选。它的结构简单,易于扩展,而其中的AJAX技术更是让开发变得更加高效。在本文中,将介绍如何使用CakePHP中的AJAX。什么是AJAX?在介绍如何在CakePHP中使用AJAX之前,我们先来了解一下什么是AJAX。AJAX是“异步JavaScript和XML”的缩写,是指一种在

jquery ajax报错403是因为前端和服务器的域名不同而触发了防盗链机制,其解决办法:1、打开相应的代码文件;2、通过“public CorsFilter corsFilter() {...}”方法设置允许的域即可。

404页面基础配置404错误是www网站访问容易出现的错误。最常见的出错提示:404notfound。404错误页的设置对网站seo有很大的影响,而设置不当,比如直接转跳主页等,会被搜索引擎降权拔毛。404页面的目的应该是告诉用户:你所请求的页面是不存在的,同时引导用户浏览网站其他页面而不是关掉窗口离去。搜索引擎通过http状态码来识别网页的状态。当搜索引擎获得了一个错误链接时,网站应该返回404状态码,告诉搜索引擎放弃对该链接的索引。而如果返回200或302状态码,搜索引擎就会为该链接建立索引

ajax重构指的是在不改变软件现有功能的基础上,通过调整程序代码改善软件的质量、性能,使其程序的设计模式和架构更合理,提高软件的扩展性和维护性;Ajax的实现主要依赖于XMLHttpRequest对象,由于该对象的实例在处理事件完成后就会被销毁,所以在需要调用它的时候就要重新构建。

php用AJax和json实现登录验证的方法是:1、创建一个jsp示例文件,导入jquery依赖和fastjson依赖文件;2、新建login.js文件,获取用户名和密码文本内容;3、新建controller类,查询用户是否存在并把对象转化为json字符串类型返回给js文件;4、js判断是否成功然后进行页面跳转即可。

Vue中如何利用JSONP实现跨域请求简介由于同源策略的限制,前端在进行跨域请求时会受到一定的阻碍。JSONP(JSONwithPadding)是一种跨域请求的方法,它利用<script>标签的特性,通过动态创建<script>标签来实现跨域请求,并将响应数据作为回调函数的参数传递回来。本文将详细介绍在Vue中如何利用JSONP实

ajax同步的意思是当JavaScript代码加载到当前ajax的时候会把页面里所有的代码加载停止,页面处于假死状态,当这个ajax执行完之后,页面才会接触假死状态,代码继续运行;ajax异步的意思则是当前ajax代码运行的时候其他代码一样也可以运行。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version
Visual web development tools

Notepad++7.3.1
Easy-to-use and free code editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
