如何使web api调用在javascript中同步 [英] How make the web api call synchronous in javascript
问题描述
我在Titanium appcelerator中开发。在那个如何使web api调用在javascript中同步。
嗨Jithin,
使用 jQuery.ajax()
示例:
async 布尔值
默认:true
默认情况下,所有请求都是异步发送的(默认设置为true)。如果您需要同步请求,请将此选项设置为false。
因此,在您的请求中,您必须执行async:false而不是async:false。
返回值ajaxSubmit的值不是成功的返回值: function (){...}
。 ajaxSubmit根本不返回任何值,相当于undefined,而后者的计算结果为true。
这就是为什么表单总是被提交的原因独立于是否同步发送请求。
如果您只想提交表单,当响应为成功时,您必须从ajaxSubmit返回false然后在@halilb已经建议的成功函数中提交表单。
这些行的东西应该可以工作
function ajaxSubmit(){
var password =
.trim(
(' #employee_password' ).VAL());
I developing in Titanium appcelerator . In that How make the web api call synchronous in javascript.
Hi Jithin,
use jQuery.ajax()
Example:
async Boolean
Default: true
By default, all requests are sent asynchronously (i.e. this is set to true by default). If you need synchronous requests, set this option to false.
So in your request, you must do async: false instead of async: "false".
The return value of ajaxSubmit is not the return value of thesuccess: function(){...}
. ajaxSubmit returns no value at all, which is equivalent to undefined, which in turn evaluates to true.
And that is the reason, why the form is always submitted and is independent of sending the request synchronous or not.
If you want to submit the form only, when the response is "Successful", you must return false from ajaxSubmit and then submit the form in the success function, as @halilb already suggested.
Something along these lines should work
function ajaxSubmit() { var password =
.trim(
('#employee_password').val());
这篇关于如何使web api调用在javascript中同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!