ajax请求参数中的&字符

当使用ajax请求时,如果有参数的值为&,则需要对其进行转义,这里使用了javascript的函数escape:

1
2
3
4
<%= observe_field :select_id,
 	  :url => url_for(:action => : xxx),
	  :with => "'zone=' + escape($('select_id').options[$('select_id').selectedIndex].value)"
%>

如果$(’select_id’).options[$('select_id').selectedIndex].value中的值为Pacific Time (US & Canada),则会转义成标准的url参数:Pacific%20Time%20%28US%20%26%20Canada%29。这样就不会出现参数丢失的情况了(会将&后面的当成另一个参数的值,所以会出现params[:zone]只能得到一半值的情况)。

Monitor Your Web Site 24/7 - Receive email and SMS alerts anytime your web site goes down.

Related Posts

Leave a Reply

Monitor Your Web Site 24/7 - Receive email and SMS alerts anytime your web site goes down.

About Me

About Me
Record Technical Articles at Gooss.org.

Entries (RSS) and Comments (RSS). Valid XHTML and CSS and XFN.

© Copyright 2009 山海经. All rights reserved.

Social Bookmarks

Copyright © Designed by: Free WP Templates
Food Charts |  About Breast Milk |  Organic Food