2011-11-28 109 views
0

我对AJAX相当陌生,所以我在入门时遇到了一些问题。创建Ajax请求

基本上,我想要使用GET选项发出一个AJAX请求,并将一个URL(如admin/something.php?id=1&that=33)发送到将执行我的PHP函数的后端。

我该如何使用attr$(this).attr('id')来生成我的数据,它基本上只是抓取DIV.ID信息等?

编辑: 我怎么能把它整合到sortable函数?

$(".heriyah").sortable({ 
    handle : '.handle', 
    connectWith: ".heriyah", 
    revert: "invalid", 
    update: function(event, ui){ 
    if(($(ui.sender).attr('id') == undefined)&&($(this).attr('id') == ui.item.parent().attr('id'))){ 
     alert('UPDATE ' + $(this).attr('id') + ' ' + (ui.item.index()+1) + ' ' + $(ui.item).text()); 
    } 
}, 
+2

在这种情况下,您可能会发现[详细的AJAX文档很好的开始](http://api.jquery.com/category/ajax),特别是['jQuery.ajax()'](http:///api.jquery.com/jQuery.ajax/)方法 – Matt

回答

1

使用jquery生成ajax请求。请参阅文档here

示例代码可能是这样的:

var request = $.ajax({ 
        url: "something.php", 
        type: "GET", 
        data: {id:1,that:33} , 
        dataType: 'json', 
        contentType: "application/json; charset=utf-8" 
       }); 

request.done(function (data) { 
    //Put complete code here 
}); 

request.fail(function (jqXHR, textStatus) { 
     alert("Request failed: " + textStatus); 
}); 
+0

我编辑了我的问题。感谢您的回复! – drummer392

0

的jQuery的伎俩很简单:

$阿贾克斯({

url: "admin/something.php?id=1&that=33", 
    context: document.body, 
    success: function(data){ 
     // display the return from something.php 
     $("#myresult").html(data); 
    } 

});