简体   繁体   中英

ajax call not working with in ajax

I using the mvc controller with ajax. I perfom the task using the jquery confirm box. when i click the "ok" button its needs to the call another ajax and its link to the another controller but its not working

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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