This question already has an answer here: How do I return the response from an asynchronous call? 33 answers You should set parameter async to false . Try this code: function ajaxRefresh(actionUrl) { var succeed = false; $.ajax({ async: false, url: actionUrl, success: function() { succeed = true; }}); return succeed; } You can refactor your code a li
这个问题在这里已经有了答案: 如何返回来自异步调用的响应? 33个答案 您应该将参数async设置为false 。 试试这个代码: function ajaxRefresh(actionUrl) { var succeed = false; $.ajax({ async: false, url: actionUrl, success: function() { succeed = true; }}); return succeed; } 您可以稍微重构代码,以便您的成功回调触发取决于真/假结果的下一个操作。 例如,如果
Possible Duplicate: How to return the response from an AJAX call from a function? I am using Jquery Ajax to call a service to update a value. function ChangePurpose(Vid, PurId) { var Success = false; $.ajax({ type: "POST", url: "CHService.asmx/SavePurpose", dataType: "text", data: JSON.stringify({ Vid: Vid, PurpId: PurId }),
可能重复: 如何从函数返回AJAX调用的响应? 我正在使用Jquery Ajax调用服务来更新值。 function ChangePurpose(Vid, PurId) { var Success = false; $.ajax({ type: "POST", url: "CHService.asmx/SavePurpose", dataType: "text", data: JSON.stringify({ Vid: Vid, PurpId: PurId }), contentType: "application/json; charset=utf-8",
This question already has an answer here: How do I return the response from an asynchronous call? 33 answers AJAX is asynchronous by default, you cannot return a value from the callback without making a synchronous call, which you almost certainly don't want to do. You should supply a real callback function to the success: handler, and put your program logic there. var pinNumber = $.a
这个问题在这里已经有了答案: 如何返回来自异步调用的响应? 33个答案 AJAX默认是异步的,你不能在不进行同步调用的情况下从回调中返回一个值,这几乎是你不想做的。 您应该为success:处理程序提供一个真正的回调函数,并将您的程序逻辑放在那里。 var pinNumber = $.ajax({ type: "POST", url: "data.php", data: "request_type=generator", async: false }).responseText; jQuery('.pin_generated_tab
This question already has an answer here: How do I return the response from an asynchronous call? 33 answers So, this question has been asked a million times over, and I'm sure that everyone (myself included) tried this once. It is just the nature of an asynchronous call, you can't use their results as a return value. Thats why they have you passing in a function that gets the res
这个问题在这里已经有了答案: 如何返回来自异步调用的响应? 33个答案 所以,这个问题已经被提出了一百万次,我确信每个人(包括我自己)都曾尝试过这一次。 这只是异步调用的本质,您不能将它们的结果用作return值。 这就是为什么他们让你传递一个函数来获得调用的结果,他们也不能return它! 另请注意, elqTracker.pageTrack()函数调用返回IMMEDIATELY,因此您的returnValue是简单的undefined 。 大多数人(参见d
This question already has an answer here: How do I return the response from an asynchronous call? 33 answers With jQuery 1.5, you can use the brand-new $.Deferred feature, which is meant for exactly this. // Assign handlers immediately after making the request, // and remember the jqxhr object for this request var jqxhr = $.ajax({ url: "example.php" }) .success(function() { alert("succe
这个问题在这里已经有了答案: 如何返回来自异步调用的响应? 33个答案 使用jQuery 1.5,您可以使用全新的$.Deferred功能,这是$.Deferred用于此目的的功能。 // Assign handlers immediately after making the request, // and remember the jqxhr object for this request var jqxhr = $.ajax({ url: "example.php" }) .success(function() { alert("success"); }) .error(function() { alert("error"); }) .
This question already has an answer here: How do I return the response from an asynchronous call? 33 answers 调用getJSON ,只有在响应后才能获得值。 var myjson; $.getJSON("http://127.0.0.1:8080/horizon-update", function(json){ myjson = json; }); $.getJSon expects a callback functions either you pass it to the callback function or in callback function assign it to global variale. var glob
这个问题在这里已经有了答案: 如何返回来自异步调用的响应? 33个答案 调用getJSON ,只有在响应后才能获得值。 var myjson; $.getJSON("http://127.0.0.1:8080/horizon-update", function(json){ myjson = json; }); $ .getJSon需要一个回调函数,或者将其传递给回调函数,或者在回调函数中将其分配给全局变量。 var globalJsonVar; $.getJSON("http://127.0.0.1:8080/horizon-update", function(json){
This question already has an answer here: How do I return the response from an asynchronous call? 33 answers What you expect is the synchronous (blocking) type request. var it_works = false; jQuery.ajax({ type: "POST", url: 'some_file.php', success: function (data) { it_works = true; }, async: false // <- this turns it into synchronous }); // Execution is BLOCKED until
这个问题在这里已经有了答案: 如何返回来自异步调用的响应? 33个答案 你期望的是同步 (阻塞)类型的请求。 var it_works = false; jQuery.ajax({ type: "POST", url: 'some_file.php', success: function (data) { it_works = true; }, async: false // <- this turns it into synchronous }); // Execution is BLOCKED until request finishes. // it_works is available alert(it_works); 请
This question already has an answer here: How do I return the response from an asynchronous call? 33 answers Use callbacks. Something like this should work based on your sample code. function someFunc() { callAjaxfunc(function() { console.log('Pass2'); }); } function callAjaxfunc(callback) { //All ajax calls called here onAjaxSuccess: function() { callback(); };
这个问题在这里已经有了答案: 如何返回来自异步调用的响应? 33个答案 使用回调。 像这样的东西应该基于你的示例代码工作。 function someFunc() { callAjaxfunc(function() { console.log('Pass2'); }); } function callAjaxfunc(callback) { //All ajax calls called here onAjaxSuccess: function() { callback(); }; console.log('Pass1'); } 这将打印Pass1立即(假设AJAX请求
This question already has an answer here: How do I return the response from an asynchronous call? 33 answers Its undefined because, console.log(response) runs before doCall(urlToCall); is finished. You have to pass in a callback function aswell, that runs when your request is done. First, your function. Pass it a callback: function doCall(urlToCall, callback) { urllib.request(urlTo
这个问题在这里已经有了答案: 如何返回来自异步调用的响应? 33个答案 它的undefined因为, console.log(response)在doCall(urlToCall);之前运行doCall(urlToCall); 完成。 您还必须传递回调函数,该函数在请求完成时运行。 首先,你的功能。 通过回调: function doCall(urlToCall, callback) { urllib.request(urlToCall, { wd: 'nodejs' }, function (err, data, response) {
Beginner here, I'm trying to build an app that creates playlists for users when an address is inputted. The SongKick API fetches artists performing within X miles of that location and then feeds the artists into the Spotify API in order to create a playlist for the user. You'd need a Spotify account in order to use this app and I figured the main page would be a Log In form for a Spoti
这里初学者,我试图建立一个应用程序,当地址输入时为用户创建播放列表。 SongKick API获取在该位置X英里内执行的艺术家,然后将这些艺术家提供给Spotify API,以便为用户创建播放列表。 您需要一个Spotify帐户才能使用此应用程序,并且我认为主页面是Spotify帐户的登录表单。 我正在查看文档,我对它有点困惑。 来自Spotify API的认证指南 我也在看这个具体的例子 从上面的例子中,我了解授权是如何工作的,但如果我