如何传递我正在使用jquery-ajax的此特定变量 [英] How can I pass this specific variable I'm using jquery-ajax

查看:123
本文介绍了如何传递我正在使用jquery-ajax的此特定变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将"passedThisValue"传递给我的"start_battle"函数,并在我的"Rematch"中使用"start_battle"函数.但是模态只是挂为什么会这样呢?有什么问题吗?请帮忙! :)谢谢.

I want to pass the "passedThisValue" to my "start_battle" function and use the "start_battle" function in my "Rematch". But the modal just hangs why is this happening? what could be wrong? Please help! :) Thank you.

代码:

function start_battle(){
    $.ajax({
        data: {
            receivePassedValue: passedThisValue
        },
        success: function(data){

        }
    });
}
$("#start_battle").click(function() {
    $.ajax({
        success: function(data){
            var toAppend = '';
            if(typeof data === "object"){
                var passedThisValue = '';
                for(var i=0;i<data.length;i++){
                    passedThisValue = data[i]['thisValue']; 
                }

                start_battle(); // can I still get the passedThisValue?

            }
        }
    });
    $("#battle").dialog({
        modal:true,
        buttons: {
            "Rematch": function(){
                start_battle(); // can I still get the passedThisValue?
            }
        }
    });
    $("#battle").show(500);
});

推荐答案

调用函数时,不使用function start_battle();,而只使用start_battle();.

When you call a function, you don't use function start_battle();, you just use start_battle();.

将值传递给函数时,需要使用以下语法:start_battle(param1, param2);.

When you pass a value to a function, you need to use this syntax: start_battle(param1, param2);.

要从函数中获取值时,需要在函数中返回它,如下所示:

When you want to get a value from a function, you need to return it in the function, like so:

function start_battle(param1) {
    // Do something
    return param1;
}

当您要存储从函数返回的值时,可以执行以下操作:var returned = start_battle(param1);

When you want to store a returned value from a function, you do something like: var returned = start_battle(param1);

事实上,您不知道模态为何会挂起,这意味着您没有检查浏览器的错误控制台,该控制台可以保存一些非常重要的错误信息.尝试检查并在此处发布,以便我们可以看到当前的问题

And the fact that you don't know why the modal just hangs, means that you didn't check the browser's error console, which can hold some pretty important information on what's wrong. Try checking that and posting here so we can see the current problem

这篇关于如何传递我正在使用jquery-ajax的此特定变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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