以下のJqueryのプロトタイプコードに相当するものを教えてください。
var myAjax = new Ajax.Updater('abc', '/billing/add_bill_detail', {
method: 'get',
parameters: pars,
insertion: Insertion.Bottom
});
Jqueryを使用して同じアクションを実行したい。
前もって感謝します。
以下のJqueryのプロトタイプコードに相当するものを教えてください。
var myAjax = new Ajax.Updater('abc', '/billing/add_bill_detail', {
method: 'get',
parameters: pars,
insertion: Insertion.Bottom
});
Jqueryを使用して同じアクションを実行したい。
前もって感謝します。
jQuery では、Ajax は次のように使用します。
$.ajax({
url: "/billing/add_bill_detail",
type: "get",
dataType: "html",
data: {"pars" : "abc"},
success: function(returnData){
$("#abc").html(returnData);
},
error: function(e){
alert(e);
}
});
abc が div の ID の場合は #abc を使用し、abc がクラスの場合は .abc を使用します。
returnData を HTML の好きな場所に配置できます。
jQuery.ajax({...}) or $.ajax({...})
これ以外のようにajaxを使用するいくつかの方法がありますこれらのいくつかの簡略化されたバージョンもあります:
$.get()
またjQuery.get()
$.post()
またjQuery.post()
$.getJSON()
またjQuery.getJSON()
$.getScript()
またjQuery.getScript()
$ = jQuery
どちらも同じです。
使用してmethod : 'get',
いるので、使用することをお勧めしますが、$.ajax({...})
この$.get()
スクリプトの上にjQueryを含めることを忘れないでください。そうしないと、ajax関数が機能しません。スクリプトをdocreadyハンドラーで囲んでみてください$(function(){})
。
'abc'
あなたがそれを説明することができれば
これを追加してみてください$.ajax()
:
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
$(function(){
$.ajax({
type: "GET",
url: "/billing/add_bill_detail",
data: pars,
dataType: 'html'
success: function(data){
$('#abc').html(data); //<---this replaces content.
},
error: function(err){
console.log(err);
}
});
});
</script>
またはと$.get()
:
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
$(function(){
$.get("/billing/add_bill_detail", {data: pars}, function(data) {
$('#abc').html(data); //<---this replaces content.
}, "html");
});
</script>
または、より単純に次の.load()
方法を使用します。
$('#abc').load('/billing/add_bill_detail');
$(function(){
$.ajax({
type: "GET",
url: "abc/billing/add_bill_detail",
data: data,
success: function(data){
alert(data);
}
});
});