Mark Topper
Mark Topper

Reputation: 347

.split(); error when making a function run another function

I have a problem with my .split(); method.

I call this function:

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

Here is the related functions:

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]));
    });
}

Then I run that, I get the following error:

Uncaught TypeError: Cannot call method 'split' of undefined 

I noticed, that the variable id have all the informations from all the variables, for some reason. Hope this helps.

OBS: I hope my code makes sense, aswell as my question.

Upvotes: 0

Views: 97

Answers (2)

Tomer
Tomer

Reputation: 17930

You are passing only one value:

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

So the first parameter (id) gets it. what you need to do is this:

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

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

Upvotes: 2

user160820
user160820

Reputation: 15200

I think you are not passing the proper parameters in you function call

place_settings

that's why either settings is undefined or default_values is undefined within your

place_settings function.

Upvotes: 1

Related Questions