你可以在发送到服务器之前序列化输入值,并像这样附加任何其他参数
// serialize all inputs inside .loginForm var formData = $('.loginForm :input').serializeArray(); // add other data when on specific address if (currentUrl == "http://localhost:59746/Account/Register/") { formData.push({ name: "ReturnUrl", value: "regurl" }); } // post with formData $.post('/Account/Login',formData,function(responseData){ // do something here with responseData },'json');
的 编辑: 强> 从代码的上下文中,尝试使用上面的脚本更改下面显示的ajax请求行
$.ajax({ url: "/Account/Login", datatype: "json", type: "POST", // this is the part where the input should be appended to the form addurl: function () { if ( currentUrl == "http://localhost:59746/Account/Register/") { console.log(currentUrl) $('<input />').attr('type', 'hidden') .attr('name', "ReturnUrl") .attr('value', "regurl") .appendTo(".basketForm.loginForm");} })