views:

22

answers:

2
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.

+1  A: 

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

Val
you're right! can't believe I missed it
sdfor
anytime :) It happens to the best lol
Val
+1  A: 

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

phsiao
thanks! you were right
sdfor