暂停代码执行 [英] Pause the code execution

查看:149
本文介绍了暂停代码执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我有一个奇怪的问题,我的代码运行得太快了。请允许我解释一下(如果可以的话)。


我正在使用XMLHTTP对象,以便在用户完成会员申请表时查询数据库,基本上我想确保每个用户名是唯一的。


我有代码检查这个,XMLHTTP对象工作正常。但是,在代码完成执行之前,运行该函数的下一部分。这意味着如果项目有效或不存在我存储的数组正在填充错误。


我只检查数据库,如果验证的第一阶段返回true。目前我有一点点软糖,我已经添加了一个警告框,正如你在下面的代码中看到的,这似乎暂停代码,然后导致正确的行为。如果没有这个,我会被告知我输入的用户名是在数据库中,但系统允许我继续,因为验证标志为true,因为用户名遵循正则表达式。


这是代码

展开 | 选择 < span class =codeDivider> | Wrap | 行号

解决方案

Heya,Nathan。


尝试直接在writeResponse()内部调用setValidationList()。


参见此主题更多i nfo。



Heya,Nathan。


尝试直接在writeResponse内调用setValidationList() ()。


请参阅此主题更多信息。



我已经阅读了另一个帖子,并且忘记了异步意味着什么感觉有点傻。


麻烦我直接调用setValidationList()是因为我无法从onreadystatechange传递参数到函数中。


如果我的代码导致cde暂停一点,没有完美的警报(如果有点软糖)。这有什么有效的方法吗?


或者有一种方法可以将参数传递给从onreadystatechange调用的函数吗?如果有,那么也许我可以将我的调用setValidationList()移动到writeResponse()。这样设置glIsValid变量的代码将在调用setValidationList()函数时执行。


感谢您的帮助到目前为止,我已经学到了很多关于这种发展。

nathj


Heya,Nathan。


我直接调用setValidationList()的麻烦是我无法从onreadystatechange传递参数到函数中。



请参阅这篇文章


Hi,

I have a strange problem, my code is running too quickly. Allow me to explain (if I can).

I am using the XMLHTTP object in order to query the database as a user completes the membership application form, basically I want to ensure that each username is unique.

I have the code to check this and the XMLHTTP object is working fine. However, before the code finishes executing the next part of the function is run. this means that the array I have for storing if items are valid or not is being populated incorrectly.

I only check the database if the first stage of validation returns true. At present I have a bit of a fudge in place in that I have added an alert box, as you can see in the code below, this seems to pause the code, which then results in the correct behaviour. Without this I get told that the username I entered is in the database but the system allows me to continue because the validation flag says true because the user name followed the regular expression in place.

Here is the code

Expand|Select|Wrap|Line Numbers

解决方案

Heya, Nathan.

Try calling setValidationList() directly inside of writeResponse().

See this thread for more info.


Heya, Nathan.

Try calling setValidationList() directly inside of writeResponse().

See this thread for more info.

I have read the other thread, and felt a bit of a fool for forgetting what Asynchronous meant.

The trouble I have with calling setValidationList() directly is that I can''t pass parameters into the function from onreadystatechange.

If I code cause the cde to pause for a bit, without the alert that would be perfect (if a bit of a fudge). Is there are any effective way of doing this?

Alternatively is there a way of passing paramters into the function that is called from onreadystatechange? If there is then perhaps I can move my call to setValidationList() into writeResponse(). That way the code that sets the glIsValid variable will have executed by the time the setValidationList() function is called.

Thanks for the help so far, I have already learnt a lot more about this sort of development.
nathj


Heya, Nathan.

The trouble I have with calling setValidationList() directly is that I can''t pass parameters into the function from onreadystatechange.

See this article.


这篇关于暂停代码执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆