。分裂();使函数运行另一个函数时出错

时间:2013-01-02 16:21:18

标签: split javascript

我的.split();方法存在问题。

我称之为此功能:

get_content_ajax("html/settings.html", "#ajax", 1, "Settings page have been loaded.", "place_settings", "'settings', 'api_username', 'api_password', 'hmm, ja', 'settings'");

以下是相关功能:

function get_content_ajax(load, element, set_status, status, success_function, success_function_values) {
    element = typeof element !== 'undefined' ? element : "#ajax";
    set_status = typeof set_status !== 'undefined' ? set_status : 0;
    status = typeof status !== 'undefined' ? status : "";
    success_function = typeof success_function !== 'undefined' ? success_function : null;
    success_function_values = typeof success_function_values !== 'undefined' ? success_function_values : "";
    $("#work-station").load(load, function(response, status, xhr) {
        if (status == "success") {
            if (set_status == 1) {
                insert_to_element(element, response);
                stop_loading_img("loader");
                start_loading_img("done");
                set_loading_status(status);
                if (success_function != null && success_function != 0) {
                    window[success_function](success_function_values);
                }
            }
        } else { // status = "error"
            no_connection();
        }
    });
}


function place_settings(id, settings, default_values, page) {
    var s = settings.split(', ');
    var d = default_values.split(', ');
    $.each(s, function(index, value) { 
        //alert(index + ': ' + value + " - default value: " + d[index]); 
        insert_to_element("#" + id + " .", get_setting(value, d[index]));
    });
}

然后我运行它,我收到以下错误:

Uncaught TypeError: Cannot call method 'split' of undefined 

我注意到,由于某种原因,变量id包含来自所有变量的所有信息。希望这会有所帮助。

OBS:我希望我的代码有意义,以及我的问题。

先谢谢。

2 个答案:

答案 0 :(得分:2)

您只传递一个值:

if (success_function != null && success_function != 0) {
                    window[success_function](success_function_values);
}

所以第一个参数(id)得到它。你需要做的是:

function place_settings(data) {
   //now data contains all the information you need and you can get the values from it

var id = data['id'];
...
    });
}

答案 1 :(得分:1)

我认为你没有在函数调用中传递正确的参数

place_settings

这就是为什么settings未定义或default_values在您的

中未定义的原因
place_settings function.