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 com开发者_运维百科mon routine that doesn't know what is being passed.
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
Maybe the variable name 'ajax_arg' is also used some where else? 'ajax_arg' is a global variable.
加载中,请稍侯......
精彩评论