2010-11-29 7 views
1

jQuery、.POSTから.AJAXへの変換方法?

私は以下を持っています:

 $.post(this.href, { _method: 'delete' }, null, "script"); 

どのように変換することができますか:

$.ajax({ 
    type: "POST", 
    url: , 
    data: , 
    beforeSend: function() { 
    }, 
    success: function() { 

URLを扱う方法や_methodを追加する方法を使用しません。 .ajaxと一緒に行くの?

ありがとう

答えて

3

URLは同じままで、_method: 'delete'はデータセクションに入ります:

$.ajax({ 
    type: "POST", 
    url: this.href, 
    data: { _method: 'delete' }, 
    beforeSend: function() {}, 
    success: function() {}, 
    dataType: 'script' 
    }); 
0

は、URLやデータのパラメータは、あなたのthis.hrefと_methodsになります注意してください、私は自分のアプリケーションで使用する方法の例です:

function OnChangeRoom(RoomID) { 
    $.ajax({ 
     type: "POST", 
     url: "../server.asmx/GetWordFromRoomID", 
     data: "{'RoomID':'" + RoomID + "'}", 
     contentType: "application/json; charset=utf-8", 
     dataType: "json", 
     cache: false, 
     success: function (data) { 
      if (data.d.length == 0) 
       $('#spanWord').html(' '); 
      else 
       $('#spanWord').html('Word: ' + data.d); 
     } 
    }); 
} 
1

documentation of $.post

を "削除します"
$.ajax({ 
    type: 'POST', 
    url: url, 
    data: data, 
    success: success 
    dataType: dataType 
}); 
関連する問題