0

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;
    }
    }

    }

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

4

2 に答える 2

2

POSTを使用してメソッドを呼び出している場合AJAX、サーバー側でのリダイレクトは機能しません。

リクエストを使用してリクエストが完了した後、クライアント側でリダイレクトする必要がありますjavascript

$('#clickme').click(function (e) {
            e.preventDefault();
            indx = $("#DropDownList1 option:selected").index();
            indx += 1;
            var test = $("#DropDownList" + (indx + 1));
            var url = "/Base/sample/Hello/"
            jQuery.post(url, { name: jQuery("#name").val(), email: jQuery("#email").val(), federation: jQuery(test).val(), selectedscheme: jQuery("#DropDownList1").val() },
       function (data) {

           if (data == "shoothim") {
               window.location = "http://www.cuthishead.com"
           }
           else if(data == "shoother")
           {
                window.location = "http://www.chopherbody.com"
           }
           else if(data == "shootboth")
           {
                window.location = "http://www.fulldeath.tv"
           }
       });
于 2012-06-15T10:17:23.987 に答える
1
  • ページ メソッドからの戻り値selectedschemeまたは URL

  • window.locationjqueryのWebメソッドの結果に基づいて設定

  • WebMethodC# メソッドの属性を設定する必要があります

jQuery を使用した ASP.NET AJAX ページ メソッドの呼び出しを確認する – 例

于 2012-06-15T10:23:56.667 に答える