开发者

Use $.get() inside success: function(data) {... in $.ajax().?

Can I use $.get() or $.ajax() inside of success: function(data) {... in $.ajax() ?

Like:

$.ajax({
    url: 'ajax/test1.html',
    success: function (data) {
        $('.result').html(data);
        $.get("test2.php", function (data) {
            alert("Data Loaded: " + data);
        });
    }
});

Or

$.ajax({
    url: 'ajax/test1.html',
    success: function (data) {
        $('.result').html(data);
        $.ajax({
            url: 'ajax/test2.html',
            success: function (data) {
开发者_开发百科                $('.result').html(data);
                alert('Load was performed.');
            }
        });
  }
});

Does this work correctly? Which of those is best? If it does not work, how would I do it correctly?


Yes, it's possible to do both.

The $.get() is equivalent to:

$.ajax({
  url: url,
  data: data,
  success: success,
  dataType: dataType
});

See in http://api.jquery.com/jQuery.get/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜