Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
298 views
in Technique[技术] by (71.8m points)

javascript - 不使用异步的Ajax中断当前功能(Ajax interrupt current function without using async)

i have a custom jQuery function with callbacks, in one of them i want to do a server-side check before some event is triggered.(我有一个带有回调的自定义jQuery函数,在其中之一中,我想在触发某些事件之前进行服务器端检查。)

Something like this:(像这样:) var object = $('#object').customFunction({ onSomeEvent: function (someData) { $.ajax({ ... ... success: function(data) { if (data == ok) { return true; } else { return false; ***** } } }) }, }) **** I want this "return false;"(****我想要这个“返回假”;) to be the return of "onSomeEvent".(是“ onSomeEvent”的返回。) I know i can make the ajax call async false, save the response data in a variable, check it after the ajax and return the false then, but i really would like to avoid the async false.(我知道我可以使ajax调用async为false,将响应数据保存在变量中,在ajax之后检查它,然后返回false,但是我真的很想避免async false。) I really dont know what to try, everything i google is putting the ajax async on false.(我真的不知道该怎么尝试,我将google的所有内容都将ajax异步设置为false。) Thanks in advance for your help!(在此先感谢您的帮助!)   ask by Emepese translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

to avoid setting async to false, im using this..(为了避免将async设置为false,即时通讯使用此方法。)

my_request = $.ajax({ ... ... }) my_request.done(function(data)){ //you can set the data to global });

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...