2013-10-18 60 views
-3

沒有任何一個來自jQuery頁面的jQuery方法可以以同樣的方式工作,就像這樣。在jQuery中,這個Ajax代碼的等價物是什麼?

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); 

} 
+1

http://api.jquery.com/jQuery.ajax/ –

+1

'的jQuery( '#富')。載入('foo.php?id = 22')' – steveukx

+1

*你的*會做些什麼?給它一個去,然後如果你遇到麻煩,尋求幫助,併發布你的努力。 –

回答

1

它應該是這樣的

$.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); 
    } 
}); 
+0

相當圓潤。 –

相關問題