0

I facing small issue. How to get variable value from another function in Datatables.

My Javascript code:

var id = "";
var type = "";

show = function(id, type){ //id=5, type=3
        id = id;
        type = type;
}

var pTable = $("#example").DataTable({
    processing: true,
    serverSide: true,
    sort: true,
    ajax: {
        url: "/url/"+id+"/"+type,
        dataType:"json"
    },

Console log result:

GET: /url///;

How to get value ? Sorry for bad english.

2 Answers 2

2

Change show function like this:

show = function(_id, _type){ 
    id = _id;
    type = _type;}
Sign up to request clarification or add additional context in comments.

2 Comments

Yep, not a good idea to have arguments of the same names as variables
@chris97ong +1 It's same.
0

I solved my issue following code:

pTable.ajax.url("/url/"+id+"/"+type).load();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.