我编写了一个类,它使用 jquerypost 获取发布数据,然后执行一些 crud 操作。它可以很好地向数据库添加内容,但是在传递某些数据时它不会重定向到页面,下面是代码:
$('#clickme').click(function (e) {
e.preventDefault();
indx = $("#DropDownList1 option:selected").index();
indx += 1;
var test = $("#DropDownList" + (indx + 1));
var url = "/Base/performOperations/shootme/"
jQuery.post(url, { name: jQuery("#name").val(), email: jQuery("#email").val(), federation: jQuery(test).val(), selectedscheme: jQuery("#DropDownList1").val() },
function (data) {
if (data == scheme1) {
window.location = "http://www.openme.com"
}
});
});
namespace pw
{
public class performOperations
{
public static string ShootMe() {
HttpRequest post = HttpContext.Current.Request;
string name = post["name"];
string email = post["email"];
string selectedscheme = post["selectedscheme"];
string federation = post["federation"];
string conn = System.Configuration.ConfigurationManager.AppSettings["mydb"];
string sql = "INSERT INTO dbo.mydb(Email,Name,schemes,LoginDate,schemeType) VALUES(@email,@name,@scheme,@dateTime,@federation)";
SqlHelper.ExecuteNonQuery(conn, CommandType.Text, sql,
new SqlParameter("@email", email),
new SqlParameter("@name", name),
new SqlParameter("@scheme", selectedscheme),
new SqlParameter("@dateTime", DateTime.Now),
new SqlParameter("@federation", federation));
return selectedscheme;
}
}
}
任何为什么不发生重定向的想法,或者我是否以错误的方式进行操作,一旦数据注入数据库,我需要重定向到特定页面。任何帮助将不胜感激