pecifying the Data Type for AJAX Requests
Ajax Event
jquery ajax api
注意一下的參數
cache
Added in jQuery 1.2, if set to false it will force the pages that you request to not be cached by the browser.
complete
A function to be called when the request finishes (after success and error callbacks are executed). The function gets passed two arguments: The XMLHttpRequest object and a string describing the type of success of the request.
contentType
When sending data to the server, use this content-type. Default is "application/x-www-form-urlencoded", which is fine for most cases.
data
Data to be sent to the server. It is converted to a query string, if not already a string. It's appended to the url for GET-requests. See processData option to prevent this automatic processing. Object must be Key/Value pairs. If value is an Array, jQuery serializes multiple values with same key i.e. {foo:["bar1", "bar2"]} becomes '&foo=bar1&foo=bar2'.
processData
By default, data passed in to the data option as an object (technically, anything other than a string) will be processed and transformed into a query string, fitting to the default content-type "application/x-www-form-urlencoded". If you want to send DOMDocuments, or other non-processed data, set this option to false.
password
A password to be used in response to an HTTP access authentication request.
username
A username to be used in response to an HTTP access authentication request.
2009年2月14日 星期六
2008年12月15日 星期一
2008年9月4日 星期四
render page update
[view]
function ajax_create(act, pos, goals) {
$.ajax({
url: '/goals/'+act,
type: 'POST',
data: goals,
dataType: 'html',
success:function(html){
$(pos).after(html);
$('td.goal_del').unbind('click', goal_del).bind('click', goal_del);
$('td.goal_up_tmp').unbind('click', goal_up ).bind('click', goal_up);
$('td.goal_down_tmp').unbind('click', goal_down).bind('click', goal_down);
}
});
}
[controller]
render :partial => 'member/temp_goal', :locals => {:g => new_goal}
[view]
<%= observe_field :target_type_target_type_id, :on => "change",
:url => {:action => :update_target_list},
:with => "{target_type_id: value, target_cat_id: $('target_type_target_cat_id').value}"%>
(用page 寫 js)
[controller]
render :update do |page|
page.replace_html 'target_type_target_id', :partial => 'target_type_select', :locals => {:types => target_list}
end
[view]
function test() {
$.ajax({
url: '/alert/test',
type: 'GET',
success : function(html){
alert(html);
}
});
}
[controller]
render :action => 'test', :layout => false
[test view]
<% response.headers['Content-Type'] = "text/javascript" %>
alert(<%=1+1 %>);
[view]
function test() {
$.ajax({
url: '/alert/test',
type: 'GET',
dataType: 'script'
});
}
[controller]
render :action => 'test', :layout => false
[test view]
<% response.headers['Content-Type'] = "text/javascript" %>
alert(<%=1+1 %>);
[view]
function test() {
$.ajax({
url: '/alert/test',
type: 'GET',
dataType: 'script'
});
}
[controller]
render :update do |page|
page.alert('cccccc') #page << "alert('cccc');" the same end
[view]
function test() {
$.ajax({
url: '/alert/test',
type: 'GET',
dataType: 'script'
});
}
[controller]
def test
#nothing
end
[test view] test.rjs
page << "alert('cccccc');"
訂閱:
文章 (Atom)