简体   繁体   English

ajax调用无法在ajax中使用

[英]ajax call not working with in ajax

I using the mvc controller with ajax. 我在ajax中使用了mvc控制器。 I perfom the task using the jquery confirm box. 我使用jquery确认框执行任务。 when i click the "ok" button its needs to the call another ajax and its link to the another controller but its not working 当我单击“确定”按钮时,它需要调用另一个ajax并链接到另一个控制器,但是它不起作用

Sample code: 样例代码:

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

i have tried your code but it worked for me.the difference is that you need to pass data in correct format. 我已经尝试过您的代码,但对我有用。不同之处在于您需要以正确的格式传递数据。 data:data or data:{ data:data } but not 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
        { }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM