我寫過一個類,它使用jquerypost獲取發佈數據,然後執行一些crud操作。它工作正常添加的東西到數據庫中,但經過一定的數據時,它不重定向到頁面,下面的代碼:HttpContext.Current.Response.Redirect在類中的問題
$('#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;
}
}
}
爲什麼重定向犯規發生,還是我在錯誤做任何想法方式,我需要重定向到一個特定的頁面,一旦數據被注入數據庫。 任何幫助將不勝感激
我已經在我的問題中添加了jquery,所以你的意思是我應該返回d數據到jquery,然後執行if else語句。 –
是的。正確... –
如何檢查函數數據,我的意思是我如何調試jquery,我需要知道如果該方案正在傳遞給函數,因爲目前沒有任何事情發生 –