开发者

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

开发者 https://www.devze.com 2023-04-07 16:44 出处:网络
Can I use $.get() or $.ajax() inside of success: function(data) {... in $.ajax() ? Like: $.ajax({ url: \'ajax/test1.html\',

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

精彩评论

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