English 中文(简体)
Ajax作为javascript比较的一部分发挥作用
原标题:Ajax function as part of a javascript comparison

我 m忙 into忙,如果说话,不会把结果适当退回到 j。

这里的问题是,我们有一个数据库功能,它正在产生长足的假设/声明,其摘录如下。

if(1==1 && (GenericAjaxValidation("System.Yes")=="Y")) {do stuff}

The 1==1 is the result of something that happened in the database, so just ignore that bit. The GenericAjaxValidation call is the piece that is giving us issues The javascript function that it calls is below.

function GenericAjaxValidation(token) {

    $.ajax({
        type: "Post",
        url:  ../FormAjax/GetAjaxValResult ,
        data: {TOKEN:token,FormId:formDisplay.FormID,FormLayoutId:formDisplay.FormLayoutID},
        dataType: "json",
        timeout: 30000,
        async:false,
        success: function(obj) {
            result=obj.Object.ReturnValue;
        },
        error: function(obj) {

            return false;
        },
        complete: function(){
        return result;
        }
    });

}

整个进程是作为交换活动的一部分而启动的,如果说没有问题,我们就能够发言。 如果我把一个裂缝点推到支气球功能中的话,它就会妥善处理,并归还它本应使用的“Y”。 然而,当我回头看发言时,发言失败了。 我认为,这比以往更小,而且认识到,它总是将通用阿贾西瓦利德的结果视为未界定。 事实上,为了测试它,我改变了对平等进行检验的说法是否未经界定,它是否成功。

我怀疑的是,尽管 as笑:假冒造成该单一功能的其余部分等待返回,但似乎在等待声明时,评估却不等待实际价值。 我在寻找这个网络上大约半小时,试图找到能够肯定某种方式的任何东西,但我的谷歌-未来今天却失败了。

So, my question is this: is there a way to make this work? or does javascript simply not play nice with this process.

最佳回答

Try(未经测试的代码):

function GenericAjaxValidation(token) {
    var result
    $.ajax({
        type: "Post",
        url:  ../FormAjax/GetAjaxValResult ,
        data: {TOKEN:token,FormId:formDisplay.FormID,FormLayoutId:formDisplay.FormLayoutID},
        dataType: "json",
        timeout: 30000,
        async:false,
        success: function(obj) {
            result=obj.Object.ReturnValue;
        },
        error: function(obj) {

            result = false;
        }
    });
    return result;
}

(编辑:正如@toby所指出的,complete 洗手没有必要,也不做任何事情。

问题在于GenericAjaxValidationn t re any。 该表的<代码>完整功能是这种回报。 仅凭直接职能而不是附加功能的回报,即<代码>GenericAjaxValid才刚刚完成。

为了更清楚起见,您的原始代码可以书面写成功能上等同的陈词(本样本中的注和您的原始代码,result<>/code>是一个全球变量):

function GenericAjaxValidation(token) {
    $.ajax({
        type: "Post",
        url:  ../FormAjax/GetAjaxValResult ,
        data: {TOKEN:token,FormId:formDisplay.FormID,FormLayoutId:formDisplay.FormLayoutID},
        dataType: "json",
        timeout: 30000,
        async:false,
        success: onSuccess,
        error: onError,
        complete: onComplete
    });
    //No return statement
}
function onSuccess(obj) {
    result=obj.Object.ReturnValue;
}
function onError(obj) {
    return false;
}
function onComplete(){
    return result;
}

As you can see, GenericAjaxValidation never returns anything.

问题回答

<代码>return 报表inside“$.ajax()”呼唤功能。 由于您的总体职能,这些数值已经升值,因为只有<条码>。

You could have the callbacks instead set a local variable and then return that, but really you shouldn t do synchronous ajax in the first place.

My suspicion is that jQuery is screwing you over.

我建议你去除 j子,而是在XMLHttpRequest中放置。 我可以保证,它会失败。

j Query - 简化手续,使之复杂化! 我写了自己的法典,我知道<>exactly做了些什么。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签