weixin_33704591 2017-01-24 11:59 采纳率: 0%
浏览 23

Ajax呼叫失败

I'm trying to create a jquery/ajax script. The purpose is to take data from a database, compare results in the successFunc and do the next ajax call to a mvc actionResult which would render a view according to the result. For some reason it is not working.

function GetPageData() {
$.ajax({
    type: "Post",
    url: '/Track/GetPageData',
    dataType: "json",
    data: param = "",
    success: successFunc,
    error: errorFunc
});
function successFunc(data, status) {
    alert('data; '+data+', '+'status: '+status);
    if (data == 'contact') {
        $.ajax({
            type: "Post",
            url: '/Track/Contact',
            dataType: 'json',
            success: successF,
            error: errorF
        });
        function successF() {
            alert('services')
        }
        function errorF() {
            alert('servicesFail')
        }
    }

One of ActionResults methods:

public ActionResult Contact()
    {
        return View();
    }

During debugging I can see that call is made to ActionResult Contact() but it does not render the view. Any idea why the code is not working?

  • 写回答

3条回答 默认 最新

  • 关注

    You have not ended GetPageData function after first ajax call. Write it down as below and check -

    function GetPageData() {
        debugger;
        $.ajax({
            type: "Post",
            url: '/Track/GetPageData',
            dataType: "json",
            data: param = "",
            success: successFunc,
            error: errorFunc
        });
    }
        function successFunc(data, status) {
                $.ajax({
                    type: "Post",
                    url: '/Track/Contact',
                    dataType: 'json',
                    success: successF,
                    error: errorF
                });
    
        }
        function successF() {
            alert('services');
        }
        function errorF() {
            alert('servicesFail');
        }
        function errorFunc() {
            alert('servicesFail');
        }
    
    评论

报告相同问题?

悬赏问题

  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥20 java在应用程序里获取不到扬声器设备