0

ajaxでmvcコントローラーを使用しています。jquery 確認ボックスを使用してタスクを実行します。「OK」ボタンをクリックすると、別のajaxと別のコントローラーへのリンクを呼び出す必要がありますが、機能しません

サンプルコード:

function button_click() {

    $.ajax({
        type: 'POST',
        url: 'url',
        data: {data},
        dataType: 'json',
        success: function (data) {
          if (data.success == true) { call(data); }
                            else { alert(data.data); }

          }
    });
}

function call(data)
{
var ans =  confirm(data)
if(ans)
{
  $.ajax({
 type: 'POST',
        url: '@(Url.Action("StudentList", new { Area = "Mec", Controller = "HOD" }))',, // this url not goes to the controller
        data: {data},
        dataType: 'json',
        success: function (data) {
          if (data.success == true) { alert(data.data); }
                            else {  }

          }
    });
} else { }
}
4

1 に答える 1

0

私はあなたのコードを試しましたが、それは私のために働きました。違いはあなたが正しいフォーマットでデータを渡す必要があるということです。data:dataまたはdata:{data:data}ですが、data:{data}ではありません

     function button_click() {
        $.ajax({
            type: 'POST',
            url: 'Demo/Demo_action',
            data: { data: "what you want to pass" },
            //dataType: 'json',
            //contentType: 'application/json',
            success: function (data) {
                if (data == "hello") {
                    call(data);
                }
            }
        });
    }
    function call(data) {
        var ans = confirm(data)
        if (ans) {
            $.ajax({
                type: 'POST',
                url: '@(Url.Action("Demo_action2", new { Area = "Mec", Controller = "Home" }))',
                //url: 'Home/Demo_action2', // this url not goes to the controller
                data: { data: data },
                dataType: 'json',
                success: function (data) {
                    alert(data);
                }
            });
        }
        else
        { }
    }
于 2013-03-22T11:34:50.770 に答える