{"id":137,"date":"2010-05-28T16:46:07","date_gmt":"2010-05-28T08:46:07","guid":{"rendered":"http:\/\/www.xiaojia.info\/?p=137"},"modified":"2010-05-29T09:36:56","modified_gmt":"2010-05-29T01:36:56","slug":"aspjquery","status":"publish","type":"post","link":"https:\/\/www.luja.cc\/?p=137","title":{"rendered":"asp\u7528jquery\u8f93\u51fahtml\u4e2d\u6587\u662f\u4e71\u7801\u7684\u95ee\u9898"},"content":{"rendered":"<p>\u4eca\u5929\u9047\u5230\u4e86\u4e00\u4e2a\u95ee\u9898\uff0c\u5728asp\u91cc\u7528jquery\u8f93\u51fa\u4e00\u6bb5\u4e2d\u6587\uff0c\u7adf\u7136\u662f\u4e71\u7801<br \/>\n$(&#8220;#comment&#8221;).html(&#8220;\u4e2d\u6587&#8221;)<br \/>\n\u89e3\u51b3\u65b9\u6cd5\uff1a<br \/>\n\u6211\u4eec\u5fc5\u987b\u6307\u660e\u9001\u51fa\u7684\u662f\u4ec0\u4e48\u7f16\u7801\u6d41\u3002<br \/>\n\u6240\u4ee5\u5728asp\u91cc\u9762\u8981\u52a0\u4e0a\u8fd9\u53e5\uff1a<br \/>\nResponse.Charset = &#8220;GB2312&#8221;<br \/>\n<!--more--><\/p>\n<p>\u4e00\u4e0b\u662f\u8f6c\u8f7d\u8fc7\u6765\u7684\u6587\u7ae0\uff0c\u4f9b\u53c2\u8003\u5b66\u4e60\u3002<br \/>\n<strong>asp jquery\u4e71\u7801<\/strong><br \/>\n\u4ea7\u751f\u4e71\u7801\u4e3b\u8981\u67092\u4e2a\u539f\u56e0\uff1a<br \/>\n\uff081\uff09xtmlhttp \u8fd4\u56de\u7684\u6570\u636e\u9ed8\u8ba4\u7684\u5b57\u7b26\u7f16\u7801\u662f\u201cutf-8\u201d\uff0c\u5982\u679c\u524d\u53f0\u9875\u9762\u662f\u201cgb2312\u201d\u6216\u8005\u5176\u5b83\u7f16\u7801\u6570\u636e\u5c31\u4f1a\u4ea7\u751f\u4e71\u7801<br \/>\n\uff082\uff09post \u65b9\u6cd5\u63d0\u4ea4\u6570\u636e\u9ed8\u8ba4\u7684\u5b57\u7b26\u7f16\u7801\u662f\u201cutf-8\u201d\uff0c\u5982\u679c\u540e\u53f0\u662f\u201cgb2312\u201d\u6216\u5176\u4ed6\u7f16\u7801\u6570\u636e\u5c31\u4f1a\u4ea7\u751f\u4e71\u7801<\/p>\n<p>     \u89e3\u51b3\u7684\u529e\u6cd5\u5c31\u662f\u5728\u9001\u51fa\u7684\u6d41\u91cc\u9762\u52a0\u4e00\u4e2aHEADER\uff0c\u6307\u660e\u9001\u51fa\u7684\u662f\u4ec0\u4e48\u7f16\u7801\u6d41\uff0c\u8fd9\u6837XMLHTTP\u5c31\u4e0d\u4f1a\u4e71\u641e\u4e86\u3002<\/p>\n<p>PHP\uff1aheader(&#8216;Content-Type:text\/html;charset=GB2312&#8217;);<br \/>\nASP\uff1aResponse.Charset(&#8220;GB2312&#8221;)<br \/>\nJSP\uff1aresponse.setHeader(&#8220;Charset&#8221;,&#8221;GB2312&#8243;);<\/p>\n<p>     \u4e0a\u9762\u6240\u8bf4\u7684\u65b9\u6cd5\uff0c\u5728\u5f02\u6b65\u83b7\u53d6\u6570\u636e\u65f6\u662f\u6709\u6548\u7684\uff0c\u4f46\u662f\uff0c\u5728\u5f02\u6b65\u63d0\u4ea4\u6570\u636e\u65f6\u5f80\u5f80\u4f1a\u5931\u6548\uff0c\u54ea\u6015\u5728\u6211\u4eec\u63d0\u4ea4\u6570\u636e\u65f6\u7528\u4e0a\u4e86 Javascript \u7684\u51fd\u6570 escape() \u5bf9\u63d0\u4ea4\u7684\u6570\u636e\u8fdb\u884c\u7f16\u7801\u3002\u56e0\u6b64\uff0c\u89e3\u51b3Ajax\u4e71\u7801\u6700\u5b8c\u7f8e\u7684\u65b9\u6cd5\uff0c\u770b\u6765\u53ea\u6709\u5c06\u7f51\u9875\u7684\u7f16\u7801\u6539\u7528\u201cutf-8\u201d\uff0c\u81f3\u5c11\u662f\u4e0e Ajax \u76f8\u5173\u7684\u6240\u6709\u7f51\u9875\u5fc5\u987b\u7528\u201cutf-8\u201d\u7f16\u7801\u3002<\/p>\n<p>     \u4e0b\u9762\u662f\u53e6\u5916\u4e00\u79cd\u65b9\u6cd5\uff1a<\/p>\n<p>     \u5076\u7528 jQuery \u7684 $.post() \u65b9\u6cd5\u5f02\u6b65\u83b7\u53d6\u6570\u636e\u65f6\uff0c\u5728\u670d\u52a1\u7aef\uff08asp\uff09\u52a0\u4e0a Response.Charset=&#8221;GB2312&#8243; \uff0c\u8fd4\u56de\u663e\u793a\u6b63\u5e38\uff0c\u4e0d\u8fc7\uff0c\u5728\u7528 $.post() \u65b9\u6cd5\u63d0\u4ea4\u6570\u636e\u65f6\uff0c\u670d\u52a1\u7aef\u63a5\u6536\u5230\u7684\u6570\u636e\u5c31\u53d8\u6210\u4e86\u4e71\u7801\uff08\u670d\u52a1\u7aef\u52a0\u4e86 Response.Charset=&#8221;GB2312&#8243; \u4e5f\u4e00\u6837\uff09\uff0c\u6839\u636e\u4ee5\u524d\uff08\u5728\u7528jQuery\u4e4b\u524d\uff09\u7684\u7ecf\u9a8c\uff0c\u6211\u5c31\u7528 Javascript \u51fd\u6570 escape() \u5c06\u63d0\u4ea4\u7684\u6570\u636e\u8fdb\u884c\u4e86\u7f16\u7801\uff0c\u8fd9\u56de\u60c5\u51b5\u597d\u4e86\u4e00\u4e9b\uff0c\u670d\u52a1\u7aef\u63a5\u6536\u5230\u7684\u6570\u636e\u53d8\u6210\u4e86\u201cxx%x%x%\u201d\u3002\u5076\u60f3\u4e86\u60f3\uff0c\u4ee5\u524d\u8fd9\u79cd\u65b9\u6cd5\u6709\u6548\uff0c\u5e94\u8be5\u662f ASP \u7684 Request() \u65b9\u6cd5\u4f1a\u81ea\u52a8\u8fdb\u884c\u76f8\u5e94\u7684\u89e3\u7801\u3002\u56e0\u6b64\uff0c\u5982\u679c\u6211\u80fd\u5728 ASP \u4e0b\u7528 Javascript \u7684\u51fd\u6570 unescape() \u8fdb\u884c\u89e3\u7801\uff0c\u95ee\u9898\u5e94\u8be5\u5c31\u53ef\u4ee5\u89e3\u51b3\u3002\u4e8e\u662f\uff0c\u5076\u6446\u6e21\u5e76\u82e6\u94a9\u4e86\u51e0\u5708\uff0c\u5728\u7f51\u4e0a\u53d1\u73b0\u4e86\u4e2a\u4e0d\u9519\u7684\u51fd\u6570\uff0c\u4e00\u4e2a\u7528 ASP \u5b9e\u73b0\u7684\u548c Javascript \u4e0b\u7684 unescape() \u51fd\u6570\u6709\u76f8\u540c\u529f\u80fd\u7684\u51fd\u6570\uff0c\u6362\u53e5\u8bdd\u8bf4\uff0c\u662f\u4e00\u4e2a\u53ef\u4ee5\u76f4\u63a5\u5728 ASP \u4e0b\u76f4\u63a5\u89e3\u7801\u7528 Javascript \u4e0b\u7684\u51fd\u6570 escape() \u7f16\u7801\u7684\u6570\u636e\u7684\u51fd\u6570\u3002\u8bd5\u4e86\u4e00\u8bd5\uff0c\u679c\u771f\u6709\u6548\u3002<\/p>\n<p>     \u7ecf\u6d4b\u8bd5\uff0c\u6b64\u65b9\u6cd5\u4e5f\u662f\u6bd4\u8f83\u5b8c\u7f8e\u7684\u4e00\u79cd\u3002<\/p>\n<p>\u5047\u8bbe\uff1a\u63d0\u4ea4\u7684\u6570\u636e\u662f sendData = &#8220;\u5076\u662f\u4e2a\u61d2\u866b&#8221; \uff0c\u4ee5\u4e0b\u662f\u5076\u7684\u7a0b\u5e8f\u4ee3\u7801\u7247\u65ad\uff1a<\/p>\n<p>\u53d1\u9001\u7aef\uff1a<br \/>\n[code]<br \/>\nsendData = escape(&quot;\u5076\u662f\u4e2a\u61d2\u866b&quot;)<br \/>\n$.post(<br \/>\n   &quot;saveData.asp&quot;<br \/>\n   ,<br \/>\n   { sendData: sendData }<br \/>\n   function(data){<br \/>\n   alert(data);<br \/>\n   &#8230;<br \/>\n   }<br \/>\n);<br \/>\n[\/code]<br \/>\n\u670d\u52a1\u7aef\uff1a<br \/>\n[code]<br \/>\n&lt;%<br \/>\nrequestData = VBsUnEscape( Request.Form(&quot;sendData&quot;) )<br \/>\nResponse.Write requestData<br \/>\n%&gt;<br \/>\n[\/code]<br \/>\n\u524d\u524d\u540e\u540e\u90fd\u662f\u201c\u5076\u662f\u4e2a\u61d2\u866b\u201d\uff0c\u95ee\u9898\u5230\u6b64\uff0c\u53c8\u5f97\u5230\u4e86\u4e00\u4e2a\u76f8\u5bf9\u5b8c\u7f8e\u7684\u89e3\u51b3\uff08\u867d\u8bf4\u6b64\u65b9\u6cd5\uff0c\u8fd8\u662f\u6709\u4e9b\u9ebb\u70e6\uff09\uff01<\/p>\n<p>\u4ee5\u4e0b\u7ed9\u51fa\u3000ASP \u4e0b\u7684 escape() \u51fd\u6570\u548c unescape() \u51fd\u6570\u7684\u5177\u4f53\u5b9e\u73b0\u65b9\u6cd5\uff1a<br \/>\n[code]<br \/>\n&lt;%<br \/>\n&#8216;escape()\u51fd\u6570\u5b9e\u73b0\uff0c\u4e0d\u53d8\u76847\u4e2a\u7b26\u53f7\uff1a *(42) +(43) -(45) .(46) \/(47) @(64) _(95)<br \/>\nFunction VBsEscape(str)<br \/>\n   dim i,s,c,a<br \/>\n   s=&quot;&quot;<br \/>\n   For i=1 to Len(str)<br \/>\n   c=Mid(str,i,1)<br \/>\n   a=ASCW(c)<br \/>\n   If (a&gt;=48 and a&lt;=57) or (a&gt;=65 and a&lt;=90) or (a&gt;=97 and a&lt;=122) Then<br \/>\n   s = s &amp; c<br \/>\n   ElseIf InStr(&quot;@*_+-.\/&quot;,c)&gt;0 Then<br \/>\n   s = s &amp; c<br \/>\n   ElseIf a&gt;0 and a&lt;16 Then<br \/>\n   s = s &amp; &quot;%0&quot; &amp; Hex(a)<br \/>\n   ElseIf a&gt;=16 and a&lt;256 Then<br \/>\n   s = s &amp; &quot;%&quot; &amp; Hex(a)<br \/>\n   Else<br \/>\n   s = s &amp; &quot;%u&quot; &amp; Hex(a)<br \/>\n   End If<br \/>\n   Next<br \/>\n   VBsEscape = s<br \/>\nEnd Function<\/p>\n<p>&#8216;unescape()\u51fd\u6570<br \/>\nFunction VBsUnEscape(str)<br \/>\n   dim i,s,c<br \/>\n   s=&quot;&quot;<br \/>\n   For i=1 to Len(str)<br \/>\n   c=Mid(str,i,1)<br \/>\n   If Mid(str,i,2)=&quot;%u&quot; and i&lt;=Len(str)-5 Then<br \/>\n   If IsNumeric(&quot;&amp;H&quot; &amp; Mid(str,i+2,4)) Then<br \/>\n   s = s &amp; CHRW(CInt(&quot;&amp;H&quot; &amp; Mid(str,i+2,4)))<br \/>\n   i = i+5<br \/>\n   Else<br \/>\n   s = s &amp; c<br \/>\n   End If<br \/>\n   ElseIf c=&quot;%&quot; and i&lt;=Len(str)-2 Then<br \/>\n   If IsNumeric(&quot;&amp;H&quot; &amp; Mid(str,i+1,2)) Then<br \/>\n   s = s &amp; CHRW(CInt(&quot;&amp;H&quot; &amp; Mid(str,i+1,2)))<br \/>\n   i = i+2<br \/>\n   Else<br \/>\n   s = s &amp; c<br \/>\n   End If<br \/>\n   Else<br \/>\n   s = s &amp; c<br \/>\n   End If<br \/>\n   Next<br \/>\n   VBsUnEscape = s<br \/>\nEnd Function<br \/>\n%&gt;<br \/>\n[\/code]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4eca\u5929\u9047\u5230\u4e86\u4e00\u4e2a\u95ee\u9898\uff0c\u5728asp\u91cc\u7528jquery\u8f93\u51fa\u4e00\u6bb5\u4e2d\u6587\uff0c\u7adf\u7136\u662f\u4e71\u7801 $(&#8220;#comment&#038;#8 &hellip;<br \/><a href=\"https:\/\/www.luja.cc\/?p=137\">Read more <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[11],"tags":[173,25,26],"_links":{"self":[{"href":"https:\/\/www.luja.cc\/index.php?rest_route=\/wp\/v2\/posts\/137"}],"collection":[{"href":"https:\/\/www.luja.cc\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.luja.cc\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.luja.cc\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.luja.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=137"}],"version-history":[{"count":5,"href":"https:\/\/www.luja.cc\/index.php?rest_route=\/wp\/v2\/posts\/137\/revisions"}],"predecessor-version":[{"id":142,"href":"https:\/\/www.luja.cc\/index.php?rest_route=\/wp\/v2\/posts\/137\/revisions\/142"}],"wp:attachment":[{"href":"https:\/\/www.luja.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=137"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.luja.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=137"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.luja.cc\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}