ajax中async用於設定以非同步或同步方式執行腳本;async屬性值預設true時是非同步方式,「$.Ajax」執行後,會繼續執行ajax後面的腳本,當其屬性值設定為false時,同步請求將鎖住瀏覽器,使用者其它操作必須等待請求完成後執行。
本文操作環境:windows10系統、javascript1.8.5&&html5版、Dell G3電腦。
ajax中async有什麼作用
#async. 預設是true,即為非同步方式,$.Ajax執行後,會繼續執行ajax後面的腳本,直到伺服器端回傳資料後,觸發$.Ajax裡的success方法,這時候執行的是兩個執行緒。若要將其設為false,則所有的請求均為同步請求,在沒有傳回值之前,同步請求將鎖住瀏覽器,使用者其它操作必須等待請求完成才可以執行。
下面查看一個範例:
var temp; $.ajax({ async: false, type : "POST", url : defaultPostData.url, dataType : 'json', success : function(data) { temp=data; } }); alert(temp);
這個ajax請求為同步請求,在沒有回傳值之前,alert(temp)是不會執行的。
如果async設定為:true,則不會等待ajax要求回傳的結果,會直接執行ajax後面的語句。
不過上面設定同步請求的方法,有網友曾經回饋將async設為false後, 原意是想返回資料了再執行$.Ajax後面的腳本, 沒想到這個地方卻導致了在火狐瀏覽器下方出現閃屏(Firefox 11.0),滾動條下拉到底部觸發ajax的情況。最後只能將async:false註解掉, 也就是async為ture的情況下,成功解決了火狐瀏覽器滾動條下拉到底部觸發ajax出現閃屏的問題。
【相關教學推薦:AJAX影片教學】
以上是ajax中async有什麼作用的詳細內容。更多資訊請關注PHP中文網其他相關文章!

Include:1)AsteeplearningCurvedUetoItsVasteCosystem,2)SeochallengesWithClient-SiderEndering,3)潛在的PersperformanceissuesInsuesInlArgeApplications,4)ComplexStateStateManagementAsappsgrow和5)TheneedtokeEedtokeEedtokeEppwithitsrapideDrapidevoltolution.thereedtokeEppectortorservolution.thereedthersrapidevolution.ththesefactorsshesssheou

reactischallengingforbeginnersduetoitssteplearningcurveandparadigmshifttocoment oparchitecent.1)startwithofficialdocumentationforasolidFoundation.2)了解jsxandhowtoembedjavascriptwithinit.3)

ThecorechallengeingeneratingstableanduniquekeysfordynamiclistsinReactisensuringconsistentidentifiersacrossre-rendersforefficientDOMupdates.1)Usenaturalkeyswhenpossible,astheyarereliableifuniqueandstable.2)Generatesynthetickeysbasedonmultipleattribute

javascriptfatigueinrectismanagbaiblewithstrategiesLike just just in-timelearninganning and CuratedInformationsources.1)學習whatyouneedwhenyouneedit

tateractComponents通過theusestatehook,使用jestandReaCtTestingLibraryToSigulationsimintionsandIntractions and verifyStateChangesInTheUI.1)underthecomponentAndComponentAndComponentAndConconentAndCheckInitialState.2)模擬useruseruserusertactionslikeclicksorformsorformsormissions.3)

KeysinreactarecrucialforopTimizingPerformanceByingIneFefitedListupDates.1)useKeyStoIndentifyAndTrackListelements.2)避免使用ArrayIndicesasKeystopreventperformansissues.3)ChooSestableIdentifierslikeIdentifierSlikeItem.idtomaintainAinainCommaintOnconMaintOmentStateAteanDimpperperFermerfermperfermerformperfermerformfermerformfermerformfermerment.ChosestopReventPerformissues.3)

ReactKeySareUniqueIdentifiers usedwhenrenderingListstoimprovereConciliation效率。 1)heelPreactrackChangesInListItems,2)使用StableanDuniqueIdentifiersLikeItifiersLikeItemidSisRecumended,3)避免使用ArrayIndicesaskeyindicesaskeystopreventopReventOpReventSissUseSuseSuseWithReRefers和4)

獨特的keysarecrucialinreactforoptimizingRendering和MaintainingComponentStateTegrity.1)useanaturalAlaluniqueIdentifierFromyourDataiFabable.2)ifnonaturalalientedifierexistsistsists,generateauniqueKeyniqueKeyKeyLiquekeyperaliqeyAliqueLiqueAlighatiSaliqueLiberaryLlikikeuuId.3)deversearrayIndiceSaskeyseSecialIndiceSeasseAsialIndiceAseAsialIndiceAsiall


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

SublimeText3漢化版
中文版,非常好用

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

EditPlus 中文破解版
體積小,語法高亮,不支援程式碼提示功能

WebStorm Mac版
好用的JavaScript開發工具

Safe Exam Browser
Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。