Best method of Instantiating an XMLHttpRequest object

前端 未结 9 1518
一生所求
一生所求 2020-12-31 20:43

What is the best method for creating an XMLHttpRequest object?

It should work in all capable browsers.

9条回答
  •  醉话见心
    2020-12-31 21:12

    Use jQuery (or a similar JavaScript library). It takes care of the cross-browser compatibility issues of things like making Ajax calls.

    For example, using the jQuery Ajax call:

    $.ajax({
        url: 'document.xml',
        type: 'GET',
        dataType: 'xml',
        timeout: 1000,
        error: function(){
            alert('Error loading XML document');
        },
        success: function(xml){
            // do something with xml
        }
    });
    

提交回复
热议问题