传递变量的jQuery$.post失败 我想知道为什么: $.post(“remote.php”, {'f':a_searchtype,'partial':value}, 功能(数据){ $(“#结果”).html(数据); }); 很好。但使用变量,例如: ajax_arg={'f':a_searchtype,'partial':value}; $.post(“remote.php”, 阿贾克斯·阿格, 功能(数据){ $(“#结果”).html(数据); }); 在不相关的代码段中导致javascript错误。

传递变量的jQuery$.post失败 我想知道为什么: $.post(“remote.php”, {'f':a_searchtype,'partial':value}, 功能(数据){ $(“#结果”).html(数据); }); 很好。但使用变量,例如: ajax_arg={'f':a_searchtype,'partial':value}; $.post(“remote.php”, 阿贾克斯·阿格, 功能(数据){ $(“#结果”).html(数据); }); 在不相关的代码段中导致javascript错误。,javascript,jquery,Javascript,Jquery,第二个版本可以在不知道传递什么的公共例程中使用。ajax\u arg需要是全局变量,因此在其前面添加一个var 回答 var ajax_arg={'f':a_searchtype,'partial':value} 希望它能有所帮助也许变量名“ajax\u arg”也在其他地方使用ajax_arg'是一个全局变量。您能发布您遇到的错误吗? I am wondering why: $.post("remote.php", {'f':a_searchtype, 'partial':value

第二个版本可以在不知道传递什么的公共例程中使用。

ajax\u arg
需要是全局变量,因此在其前面添加一个var

回答
var ajax_arg={'f':a_searchtype,'partial':value}


希望它能有所帮助

也许变量名“ajax\u arg”也在其他地方使用ajax_arg'是一个全局变量。

您能发布您遇到的错误吗? 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.