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;
}
}
}
リダイレクトが行われない理由、または間違った方法でリダイレクトを行っている場合は、データがデータベースに挿入されたら、特定のページにリダイレクトする必要があります。任意の支援をいただければ幸いです