在jQuery中,这个Ajax代码的等价物是什么



jQuery页面中没有一个jQuery方法可以以相同的方式工作,就像它一样。

function enableAjaxTask(removeLink){
    var xmlhttp = false;

    if(window.XMLHttpRequest){
        xmlhttp = new XMLHttpRequest();
    }else{
        xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
    }
    xmlhttp.onreadystatechange = function(){
        if(xmlhttp.readyState === 4 && xmlhttp.status === 200){
            document.getElementById('foo').innerHTML = xmlhttp.responseText;
        }
    }

    xmlhttp.open('GET', 'foo.php?id=22', true);
    xmlhttp.send(null);
}

应该是这样的

$.ajax({
    type: 'GET', //GET/POST
    url: 'foo.php',//URL to send request
    data: 'id=12', //query parameters here, you can direct pass url: 'foo.php?id=12'
    success: function(responseText){ 
            //called if the request succeeds. also check complete ,done, error
        $('#foo').html(responseText);
    }
});
$("#foo").load('foo.php?id=22');

http://api.jquery.com/load/

最新更新