Jquery is very good at encapsulating asynchronous submission. It is very troublesome to use AJAX directly. Jquery greatly simplifies our operations and does not need to consider the surprise of the browser.
Recommend a good jQuery Ajax example article. If you forget, you can check it out.
$.post and $.get are simple methods. If you want to deal with complex logic, you can still You need to use jQuery.ajax()
1. The general format of $.ajax
$.ajax({
type: 'POST',
url: url ,
data: data ,
success: success ,
dataType: dataType
});
2. $.ajax Parameter Description
Parameter Description
url | Required. Specifies the URL to which the request should be sent. |
data | Optional. Map or string value. Specifies the data to be sent to the server with the request. |
success(data, textStatus, jqXHR) | Optional. Callback function executed when the request is successful. |
dataType |
Optional. Specifies the data type of the expected server response. Intelligent judgment (xml, json, script or html) is performed by default. |
3. Some things to note about $.ajax:
1.data There are three main methods, html splicing, jsonarray, form serialized by serialize(); specified by dataType, no intelligent judgment is specified.
2.$.ajax only submits the form in text mode. If the asynchronous submission contains
##4. My practical application example of $.ajax
1 //1.$.ajax带json数据的异步请求 2 var aj = $.ajax( { 3 url:'productManager_reverseUpdate',// 跳转到 action 4 data:{ 5 selRollBack : selRollBack, 6 selOperatorsCode : selOperatorsCode, 7 PROVINCECODE : PROVINCECODE, 8 pass2 : pass2 9 }, 10 type:'post', 11 cache:false, 12 dataType:'json', 13 success:function(data) { 14 if(data.msg =="true" ){ 15 // view("修改成功!"); 16 alert("修改成功!"); 17 window.location.reload(); 18 }else{ 19 view(data.msg); 20 } 21 }, 22 error : function() { 23 // view("异常!"); 24 alert("异常!"); 25 } 26 });27 28 29 //2.$.ajax序列化表格内容为字符串的异步请求30 function noTips(){ 31 var formParam = $("#form1").serialize();//序列化表格内容为字符串 32 $.ajax({ 33 type:'post', 34 url:'Notice_noTipsNotice', 35 data:formParam, 36 cache:false, 37 dataType:'json', 38 success:function(data){ 39 } 40 }); 41 } 42 43 44 //3.$.ajax拼接url的异步请求45 var yz=$.ajax({ 46 type:'post', 47 url:'validatePwd2_checkPwd2?password2='+password2, 48 data:{}, 49 cache:false, 50 dataType:'json', 51 success:function(data){ 52 if( data.msg =="false" ) //服务器返回false,就将validatePassword2的值改为pwd2Error,这是异步,需要考虑返回时间 53 { 54 textPassword2.html("<font>业务密码不正确!</font>"); 55 $("#validatePassword2").val("pwd2Error"); 56 checkPassword2 = false; 57 return; 58 } 59 }, 60 error:function(){} 61 }); 62 63 64 //4.$.ajax拼接data的异步请求65 $.ajax({ 66 url:'/kc/kc_checkMerNameUnique.action', 67 type:'post', 68 data:'merName='+values, 69 async : false, //默认为true 异步 70 error:function(){ 71 alert('error'); 72 }, 73 success:function(data){ 74 $("#"+ps).html(data); 75 }76 });
The above is the detailed content of jQuery Ajax instances ($.ajax, $.post, $.get). For more information, please follow other related articles on the PHP Chinese website!

JavaScript core data types are consistent in browsers and Node.js, but are handled differently from the extra types. 1) The global object is window in the browser and global in Node.js. 2) Node.js' unique Buffer object, used to process binary data. 3) There are also differences in performance and time processing, and the code needs to be adjusted according to the environment.

JavaScriptusestwotypesofcomments:single-line(//)andmulti-line(//).1)Use//forquicknotesorsingle-lineexplanations.2)Use//forlongerexplanationsorcommentingoutblocksofcode.Commentsshouldexplainthe'why',notthe'what',andbeplacedabovetherelevantcodeforclari

The main difference between Python and JavaScript is the type system and application scenarios. 1. Python uses dynamic types, suitable for scientific computing and data analysis. 2. JavaScript adopts weak types and is widely used in front-end and full-stack development. The two have their own advantages in asynchronous programming and performance optimization, and should be decided according to project requirements when choosing.

Whether to choose Python or JavaScript depends on the project type: 1) Choose Python for data science and automation tasks; 2) Choose JavaScript for front-end and full-stack development. Python is favored for its powerful library in data processing and automation, while JavaScript is indispensable for its advantages in web interaction and full-stack development.

Python and JavaScript each have their own advantages, and the choice depends on project needs and personal preferences. 1. Python is easy to learn, with concise syntax, suitable for data science and back-end development, but has a slow execution speed. 2. JavaScript is everywhere in front-end development and has strong asynchronous programming capabilities. Node.js makes it suitable for full-stack development, but the syntax may be complex and error-prone.

JavaScriptisnotbuiltonCorC ;it'saninterpretedlanguagethatrunsonenginesoftenwritteninC .1)JavaScriptwasdesignedasalightweight,interpretedlanguageforwebbrowsers.2)EnginesevolvedfromsimpleinterpreterstoJITcompilers,typicallyinC ,improvingperformance.

JavaScript can be used for front-end and back-end development. The front-end enhances the user experience through DOM operations, and the back-end handles server tasks through Node.js. 1. Front-end example: Change the content of the web page text. 2. Backend example: Create a Node.js server.

Choosing Python or JavaScript should be based on career development, learning curve and ecosystem: 1) Career development: Python is suitable for data science and back-end development, while JavaScript is suitable for front-end and full-stack development. 2) Learning curve: Python syntax is concise and suitable for beginners; JavaScript syntax is flexible. 3) Ecosystem: Python has rich scientific computing libraries, and JavaScript has a powerful front-end framework.


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

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

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

WebStorm Mac version
Useful JavaScript development tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

Dreamweaver Mac version
Visual web development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.
