sdfor
sdfor

Reputation: 6438

jQuery $.post with passed variables fails

I am wondering why:

$.post("remote.php",
    {'f':a_searchtype, 'partial':value},
    function(data){
        $("#result").html(data);
});

worksfine. but using a variable such as:

ajax_arg = {'f':a_searchtype, 'partial':value};
$.post("remote.php",
    ajax_arg,
    function(data){
        $("#result").html(data);
}); 


causes javascript errors in unrelated sections of code.

The second version can be used in a common routine that doesn't know what is being passed.

Upvotes: 0

Views: 80

Answers (2)

phsiao
phsiao

Reputation: 1567

Maybe the variable name 'ajax_arg' is also used some where else? 'ajax_arg' is a global variable.

Upvotes: 1

Val
Val

Reputation: 17522

ajax_arg needs to be global varible so add a var infront of it.

ANSWER var ajax_arg = {'f':a_searchtype, 'partial':value};

Hope it helps

Upvotes: 1

Related Questions