Óöµ½¹ý¼¸´Î´ËÀàÎÊÌ⣬ÉÏÒ»´ÎÓÃÁËJQUERYµÄJSONP£¬¶øÕâ´ÎÓÃÁËÆÕͨµÄJSд·¨£¬ÆäʵÁ½ÕßÊÇÍêÈ«Ò»ÑùµÄ£¬Ìù³öÀ´·ÖÏíÒ»ÏÂÒ²±ãÓÚÒÔºó×Ô¼º²éÕÒ
Ê×ÏÈÊÇJQUERYµÄJSONP·½·¨£º
¼ÙÉèÓÐÒ»¸ö¾²Ì¬Ò³ÃæÉϵÄijЩ¹¦ÄÜÐèҪͨ¹ýÅжÏIPÀ´ÊÚȨ·ÃÎÊ£¬¶øÕâ¸öÍøÕ¾ÊǾ²Ì¬µÄû°ì·¨×Ô¼ºÊµÏÖÅжÏIP¹¦ÄÜ£¬Õâʱºò¾Í¿ÉÒÔÓÿçÓòÀ´½â¾ö´úÂëÈçÏ£º
var CheckUrl=function(){ $.getJSON('http://www.xxx.com/Urlcheck/Url/CheckUrl?callback=?', function(json){ if(json.Status==1){ window.open(json.Url); }else{ alert(json.Message); } }
Õâ¸öº¯Êý¹¦ÄÜÊÇÓû§µã»÷ij¸öÁ´½Ó£¬µ÷ÓÃCheckUrl£¨£©ÓÃJQUERYµÄgetJSON·½·¨À´·ÃÎÊhttp://www.xxx.com/Urlcheck/Url/CheckUrl£¬callback=?ÊÇÒ»¸öÓëºǫ́·µ»ØµØÖ·Ô¼¶¨ºÃµÄÒ»¸öº¯ÊýÃû³Æ£¬½Ó×ÅÍùºó¿´¾ÍÃ÷°×ÁË¡£
¼àÊÓÒ»ÏÂÕâ¸öJSONP·½·¨Ö´ÐÐʱºò·ÃÎʵĵØÖ·¾Í»á¿´µ½ÊÇÕâÑùµÄ
Çë×¢Òâcallback=jsonp1295517950805 Õâ¸ö²ÎÊýÊÇjquery×Ô¶¯Ìí¼ÓµÄ£¬ÔÚдµÄʱºòдµÄÖ»ÊÇhttp://www.xxx.com/Urlcheck/Url/CheckUrl?callback=?,
ºǫ́½ÓÊÕÒ³Ã棺
public ActionResult CheckUrl() { //»ñÈ¡·¢³öÇëÇóµÄÔ¶³ÌÖ÷»úµÄIPµØÖ· string ip=GetUserIp(); //¾ßÌåÒµÎñÅжϵõ½·µ»ØµÄ¶ÔÏó ReStr rstr=UrlDecide.CheckUrl(ip); //×éÒ³ÃæËùÐèµÄjson´® string jsonStr = "{\"Status\": \"" + rstr.Status + "\",\"Message\": \"" + rstr.Message + "\",\"Url\": \"" + rstr.Url + "\"}"; //µÃµ½×îÖÕ·µ»ØµÄÎı¾ string parStr = Request.QueryString["callback"].ToString(); //½«Îı¾ÒÔJavaScriptµÄ·½Ê½·µ»Ø JavaScriptResult javaStr = JavaScript(parStr + "(" + jsonStr + ")"); return javaStr; }
ҪעÒâµÄÒ»µã¾ÍÊÇ·µ»ØÄÚÈݵÄContent-Type£¬±ØÐëΪtext/javascript»òÕß application/javascript£¬ÕâÀïMVCµÄActionResult ±È½Ï·½±ãµÄÌṩÁËJavaScript£¨£©·½·¨£¬webform·½Ê½µÄ»°Ö¸¶¨Ò»ÏÂResponse.ContentTypeÊôÐÔÒ²¿ÉÒÔ¡£
¿´¿´·µ»ØµÄÊý¾Ý
jsonp1295517950805({"Status": "1","Message": "¿ÉÒÔ·ÃÎÊ","Url": "www.yyy.com"}) ÉÏÃæJQUERYµÄ·½·¨Ìرð¼òµ¥ºÃÓ㬿ÉÄÜÓÃÁ˵«ÊDz»ÖªµÀÊÇÔõôʵÏֵģ¬¿´ÍêÒÔÏÂʵÏÖ¾ÍÃ÷°×JSONPµÄʵÏÖ·½Ê½ÁËvar CheckUrl=function(){ var s=document.createElement('SCRIPT'); s.src='http://www.xxx.com/Urlcheck/Url/CheckUrl?' + Math.random(); $("#script").append(s); } function L(json) { try{ var dataObj=eval("("+json+")"); if(dataObj.Status==1){ window.open(dataObj.Url); }else{ alert(dataObj.Message); }; } ); } $("#script").empty(); } catch(err) {} }HTML´úÂ룺<div id="script"></div>ºó¶Ë´úÂ룺
public ActionResult CheckUrl() { //»ñÈ¡·¢³öÇëÇóµÄÔ¶³ÌÖ÷»úµÄIPµØÖ· string ip = GetUserIp(); //¾ßÌåÒµÎñÅжϵõ½·µ»ØµÄ¶ÔÏó ReStr rstr = UrlDecide.CheckUrl(ip); //×éÒ³ÃæËùÐèµÄjson´® string jsonStr = "{\"Status\": \"" + rstr.Status + "\",\"Message\": \"" + rstr.Message + "\",\"Url\": \"" + rstr.Url + "\"}"; //½«Îı¾ÒÔJavaScriptµÄ·½Ê½·µ»Ø JavaScriptResult javaStr = JavaScript("L(" + jsonStr + ")"); return javaStr; }
ÍƼöÐÅÏ¢
- jqueryʵÏÖÍøվͼƬÀÁ¼ÓÔØ´úÂë
- jQuery Tooltips²å¼þ
- jQueryµÄ.bind()¡¢.live()ºÍ.delegate(....
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- Ä㲻ϲ»¶»ðºü£¬µ«ÓÖϲ»¶firebug£¬ÄǾ͸úÎÒÒ»ÆðÀ´ÔÚIEÉÏ....
- ¸ù¾ÝÏÔʾÆ÷·Ö±æÂʵ÷ÕûÒ³ÃæÏÔʾµÄJavascript½Å±¾
- jQuery дµÄ·ÂÐÂÀË΢²© ÏòϹö¶¯Ð§¹û¡¾×ªÔØ¡¿
- ͨÓõÄJqueryÑ¡ÔñÆ÷
- jQuery ½áºÏ Json Ìá½»Êý¾Ýµ½Webservice£¬....
- ×ÔÖÆjQueryÖÇÄÜÌáʾ²å¼þһö
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
×î½ü¸üÐÂ
- js»ñÈ¡srcÖд«µÝµÄ²ÎÊý
- jqueryʵÏÖÍøվͼƬÀÁ¼ÓÔØ´úÂë
- ÈÃä¯ÀÀÆ÷ÆÁ±ÎµôJavaScriptµÄ³ö´íÌáʾ
- github²»ÄܼÓÔØcss¡¢js½â¾ö°ì·¨
- ÎÒÖªµÀµÄJavaScript -- Éè¼Æģʽ(ÇŽÓ)Ó¦ÓÃÖ® ¨C ....
- 15¸öÖµµÃ¿ª·¢ÈËÔ±¹Ø×¢µÄjQuery¿ª·¢¼¼ÇɺÍÐĵÃ
- dz̸JavascriptÃæÏò¶ÔÏó±à³Ì
- JS¼òµ¥¶¯»·â×°
- JavaScript³õѧÕßӦעÒâµÄÆ߸öϸ½Ú
- jQuery Tooltips²å¼þ
ÆÀÂÛ