jquery.get()-使用数据作为全局变量的问题 [英] jquery.get() - problem using data as global variables
问题描述
好吧,我在网上已经读了很多书,但半身像还没有找到解决我的问题的方法: 我需要使用jquery方法get检查文件的内容是否为"nok"或为空(").我尝试过的一件事(当然没有用,但清楚地表明了我的想法)是:
Well, I've read a lot in the Net, bust still haven't found a solution to my problem: I need to check if the content of a file is "nok" or empty ("") using the jquery method get. One of the things I tried (didn't work of course, but shows clearly my idea) is:
$(document).ready(function(){
$("#submit").click(function(){
...
var captchacheck="";
$.get("/form.php", function(data){captchacheck=data;}));
if(captchacheck == "nok") hasError=true;
...
因此,请告诉我如何真正地将数据中的字符串存储到全局变量(或其他合适的结构)中,以便纯文本nok可以用于if子句中.
So please tell me how really to store the string from data into a global variable (or another suitable structure) so that the plain text nok could be used in if-clauses.
推荐答案
使用window.variablename
或jQuery样式$.variablename
分配和访问全局变量.
Use window.variablename
or in jQuery style $.variablename
to assign and access global variables.
例如
$(document).ready(function() {
$.captchacheck = "";
$("#submit").click(function() {
$.get("/form.php", function(data) {
$.captchacheck = data;
});
hasError = ($.captchacheck == "nok");
这篇关于jquery.get()-使用数据作为全局变量的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!