1

我有一个表单,更新时需要从 AJAX 提取新数据。我构建了一个函数,当 AJAX 能够访问数据时输出成功:

$(document).ready(function() {

    var results = $('#hidden').serialize();

    var url = 'index.php?option=com_mls&view=list&format=raw&' + results;

    $('#test').html(url);

    $.ajax({
        url: url,
        success: function(){
            alert('success');
        },
        error: function(){
            alert('There was an error loading your request.  <br />Please try again later.');
        }
    });
});

这已经过测试并且有效。我遇到的问题是在尝试提交用户表单时,设置了一个包含新数据的 AJAX 函数。我试过这个无济于事:

$(document).ready(function() {

    function runQuery(){  

        var results = $('#hidden').serialize();

        var url = 'index.php?option=com_mls&view=list&format=raw&' + results;

        $('#test').html(url);

        $.ajax({
            url: url,
            success: function(){
                alert('success');
            },
            error: function(){
                alert('There was an error loading your request.  <br />Please try again later.');
            }
        });
    };  

    runQuery();

});

它没有运行该runQuery();功能。

4

1 回答 1

2

它应该是

$(document).ready(function() {    
    runQuery();
});

function runQuery(){  

        var results = $('#hidden').serialize();

        var url = 'index.php?option=com_mls&view=list&format=raw&' + results;

        $('#test').html(url);

        $.ajax({
            url: url,
            success: function(){
                alert('success');
            },
            error: function(){
                alert('There was an error loading your request.  <br />Please try again later.');
            }
        });
    };  
于 2012-12-18T18:08:44.353 回答