½áÊø¸øÓèajaxµÄ³µ³µ
1.ÈÃмӵÄÄÇÏî»õÆ·¸ßÁÁÏÔʾ£¬¾ÍÒªÕÒµ½Äļþ»õÆ·±»×îиü¸ÄµÄ¡£
Æäʵ¸úÌí¼ÓAjax¹¦ÄÜÒ»Ñù¼òµ¥£¬Ö»ÊÇÒª¿ç¼¸¸öÎļþϾÍÓеãÄ£ºý£¬¿öÇÒÎÒÊÇ×Ô¼ºÐ´µÄ
£¬ËùÓеķ½·¨Ãû¸ú±äÁ¿¼°²ÎÊýɶµÄ¶¼¸úÊéÉϲ»Ò»Ñù(µ«ÔÀíÒ»ÑùµÄ)£¬ËùÒÔ¼ÓÉÏÕâЩ¹¦
ÄÜÄÑÃâ»áÃÔºýЩ£¬ÕâÒ²ÕýºÃÄÜÁ·ºÃ×Ô¼ºµÄÂß¼£¬¸ü¶®µÃrailsµÄÁ÷³Ì£¬»¹ÓÐÊÕ»ñ¾ÍÊÇÒª
Ñø³ÉºÃµÄ±à³ÌÏ°¹ß£¬²»È»ÒÔºó×Ô¼ºÐ´µÄ´úÂëÏÈ˵±ðÈË¿´¶®¿´²»¶®£¬×Ô¼º¶¼ÃÔºýÁ˾Ͳ»
ºÃÁË£¡
ÒªÌí¼Ó¸ßÁÁÏÔʾЧ¹û£¬¾ÍÏÈÒªÕÒµ½Äļþ»õÆ·ÊDZ»×îиüеģ¬ÒªÔÚ»õÆ·Ìí¼Óµ½¹ºÎï³µ
Ç°°ÑÄǼþ»õÆ·µÄÏÈ´æ¸øÒ»±äÁ¿£¬Ö®ºó°ÑÄǸö±äÁ¿return³öÈ¥£¬Ö®ºóÔÚcontrollerÀïÁ¬
×ÅsessionÊý¾ÝÒ»Æð¸øÒ»¸öʵÀý±äÁ¿·½±ãÊÓͼ¸újs½Å±¾Ê¹Óá£ÔÙÖ®ºó°ÑÐèÒª¸ßÁÁÏÔʾµÄ
htmlÄÇÒ»¿é£¬»òÕßÄĸö±êÇ©¼Çס¡£Ö®ºóµ½jsÀïÃæдÉϸßÁÁÏÔʾµÄ·½·¨£¬°Ñ¶ÔÓ¦µÄid´«
µ½ÊÓͼÀÆäʵҲ²»½Ð´«£¬¾ÍÊǶÔÓ¦°É£¡
ÔÚÍøÉÏÕÒµ½
2.Òþ²Ø¹ºÎï³µ
page[:cart].visual_effect :blind_down if @haxi.xianshiche == 1
ʱ¿ÌÒª¼Çס£¬page[]Õâ¸öÀïÃæµÄ²ÎÊýÊÇÕë¶ÔÊÓͼµÄ£¬Ò²¾ÍÊÇ´æÊÓͼij¸ö±êÇ©µÄid¡£
page.repalce("cart",:partial => "cart", :object =>@cart)
µÚÒ»¸ö²ÎÊýÊDZêÇ©µÄid£¬µÚ¶þ¸öÊÇÄ£°åÃû×Ö£¬µÚÈý¸ö¾ÍÊǶÔÏ󼯺ÏÁË¡£
Òþ²Ø¹ºÎï³µÖ»ÊÇС°ÑÏ·£¬µ÷ÓÃrailsÄÚ²¿·â×°µÄÒ»¸öjsÏÔʾµÄ·½·¨£¬Ö®ºó¼ÓÉÏÒªÏÔʾµÄ
Ìõ¼þ£¬µ±È»Ìõ¼þ¿ÉÄÜÐèҪдһ¸ö·½·¨À´ÊµÏÖ¡£ÔÚÃô½ÝÀïÊDz鿴¹ºÎï³µÖÐÊÇ·ñÓÐÎïÆ·ÁË
£¬ÒªÓоͰÑÊýÖµ²é³ö£¬Ö®ºóÔÚrjsÎļþÀïµ÷ÓöøÒÑ¡£
ÒªÒþ²ØʱֻҪ°Ñdiv±êÇ©µÄÊôÐÔÉèÖÃΪ“display:none”ÕâÊÇCSSËù×ö³öµÄЧ¹û£¬rails
Ö»ÊÇÅжÏһϼ´¿É¡£
ÈËÂҪ²»¶Ïѧϰ»îµÄ²Å»á̤ʵÓÐÒÀ¿¿¸Ð£¬Éú»îÒ²³äʵ¡£
¿´µ½ÁËrailsµÄ¸¨Öú·½·¨£¬ÏëÏëÓ¦¸ÃÊÇC#µÄʱºòµ¥¶ÀµÄ¿ÉÒÔËæ±ãµ÷ÓõÄÀàÁË£¬µ«ÓÖÓÐЩ
²»Ò»Ñù£¬·ÖÉÏϼ¶µÄ£¡ÂýÂýÀí½âÖС£
3.
ÓÉÓÚ¼ÓÁËÒþ²Ø¹¦ÄÜ£¬div±êÇ©Ò»¸öÀ¨ºÅ¹ÂÁãÁãµÄÏÔʾÔÚÁËÒ»ÐУ¬ËùÒÔÏëҪȥµô£¬±ØÐëд
¸ö¸¨Öú·½·¨À´Éú³Édiv±êÇ©£¬²¢ÇÒ»¹Òª°Ñdisplay:noneÕâÊôÐÔ¼ÓÉÏ¡£
¸¨Öú·½·¨ÔÚ°ïÖúÀïд£º
def yincang_divbq(a,b = {})ÈÃÕâ·½·¨½ÓÁ©²ÎÊý£¬Ò»Ìõ¼þÅжϣ¬¶þÊÇÒ»×éÊôÐÔ¡£
if a
b["style"] = "display:none"
end
c=tag_options(b.stringify_keys)
"<div #{c}>"
end
ÓÉÕâ¸ö·½·¨¾Í¿ÉÒÔ¿´³öºÜ¶àRubyÓï·¨£¬Ê×ÏÈ£¬¶¨ÒåÒ»¸ö·½·¨ÊÇdef£¬½Ó×ÅÊÇ·½·¨Ãû£¬¶¨
Òå·½·¨½ÓÊܵ¥¸
Ïà¹ØÎĵµ£º
function Ajax(url)
{
var m_xmlReq=null;
if(window.ActiveXObject)
{
try
{
m_xmlReq = new ActiveXObject('Msxml2.XMLHTTP');
}
catch(e)
{
try{m_xmlReq = new ActiveXObject('Microsoft.XMLHTTP');}catch(e){}
}
}
else if(window.XMLHttpRequest ......
$.ajax({
type: "post",
url: loginUrl,
data: "username=" +uname + "&password=" +pwd,
async: ......
ÎÒÓÃPHPºÍAjax½áºÏ£¬Ìí¼ÓÊý¾ÝÖ®ºó£¬Ë¢ÐÂǰ̨ҳÃ棬Êý¾ÝûÓб仯¡£
ÎҸĶ¯PHP¶¯Ì¬½Å±¾£¬Ö»ÓÐÖØÐÂÕÒ¿ªIEÔÙÊäÈëµØÖ·£¬²ÅÄÜ¿´µ½Ð§¹û¡£
ÒÔÉÏÕâЩÊDz»ÊÇ»º´æµÄÔÒò°¡£¿Ôõô½â¾ö£¿
ajax»º´æÎÊÌâ½â¾ö;¾¶£º
ÊÇ»º´æµÄÎÊÌâ¡£
ÔÚ·þÎñ¶Ë¼Ó header("Cache-Control: no-cache, must-revalidate");
²¢ÇÒÔÚÄãµÄJSÌá½»²ÎÊýÖмÓËæ»ú» ......
²ÎÊý:
options
·µ»ØÖµ:
XMLHttpRequest
ʹÓÃHTTPÇëÇóÒ»¸öÒ³Ãæ¡£
ÕâÊÇjQueryµÄµÍ¼¶AJAXʵÏÖ¡£Òª²é¿´¸ß¼¶³éÏ󣬼û$.set¡¢$.postµÈ£¬ÕâЩ·½·¨¸üÒ×ÓÚÀí½âºÍʹÓᣵ«Êǹ¦ÄÜÉÏÓÐÏÞÖÆ(ÀýÈ磬ûÓдí
Îó´¦Àíº¯Êý)¡£
¾¯¸æ£ºÈç¹ûÊý¾ÝÀàÐÍÖ¸¶¨Îª"script"£¬ÄÇôPOST×Ô¶¯×ª»¯ÎªGET·½·¨¡£(ÒòΪscript»á×÷Ϊһ¸öǶÈëÒ³ ......