我正在調查可以發送什麼以及哪些不能通過jquery ajax發送,因爲它給了我錯誤的結果。起初我認爲這是與路徑字符有關。但我發現它確實不是。這是一個jQuery的bug或什麼?
因此,我寫了一個Web服務,它記錄了已發送的內容以及發送38個符號的jQuery AJAX代碼。但每次,我的網絡服務記錄不同的符號,並以不同的順序。我的代碼如下。
HTML:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<div id="original"></div>
<div id="returnedsybmols"></div>
<div id="returnedunicode"></div>
<script src="Scripts/jquery-2.0.0.min.js"></script>
<script>
$(function() {
var symbols = "! \" # $ % & ' () * + , - ./: ; <=> ? [ \ ]^_ ` { | } ~ ! ¢ £ ? \\ | §";
//var unicode ="サイトは有効なHTMLマークアップを使っていません。テキストを貼り付けてください。";
var eachsymbol = symbols.split(' ');
//alert(eachsymbol.length);
for (var i = 0; i < eachsymbol.length; i++) {
}
eachsymbol.forEach(function (t) {
$.ajax({
type: "POST",
url: "jsonstring.asmx/symbols",
data: "{'send':'" + t + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
var returnedText = msg.d;
$("#returnedsysmbols").append($("<p>").text(returnedText));
},
error: function (e) {
alert("error");
}
});
});
});
</script>
</body>
</html>
ASP:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Net;
using System.IO;
using System.Text;
using System.Xml;
using System.Text.RegularExpressions;
using System.Web.Script.Services;
namespace ASP_NET
{
/// <summary>
/// Summary description for jsonstring
/// </summary>
///
[System.Web.Script.Services.ScriptService]
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class jsonstring : System.Web.Services.WebService
{
[WebMethod]
public string symbols(string send)
{
using (StreamWriter sw = File.AppendText(@"E:\My Documents\programming\exercise\ASP_NET\ASP_NET\writeout\symbols4.txt"))
{
sw.WriteLine(send);
}
return send;
}
[WebMethod]
public string unicode(string send)
{
using (StreamWriter sw = new StreamWriter(@"E:\My Documents\programming\exercise\ASP_NET\ASP_NET\writeout\unicode.txt"))
{
sw.Write(send + " ");
}
return send;
}
}
}
顯然\」,「無法通過jQuery的過去,我嘗試使用轉義功能,但它將編碼我所有Unicode字符的任何。解決方案? 你能解釋爲什麼我的網絡服務器每次記錄不同的數字和不同的字符集?
運行情況1 「()* +, - 。 /:; < =#! %&? > [`^ {! 〜? | £§
運行情況2 $()* +, - 。 /:; <#「%& => [] _`} |!?!?!{〜¢£§
運行情況3 $ &%()* - +/<>^_}〜¢ ?£§|
run case 4 $()* +, - 。/:; &「#<? ! > = _ [`| {}〜£| ! ? ¢
你爲每個符號發送一個ajax請求。 Ajax是異步的,所以你的第二個請求可以比第一個請求先完成。 不同的數字可能是因爲請求尚未滿足或完全不滿意。使用fiddler檢查http消息 – 2013-05-01 06:16:37
嘗試在服務器上使用客戶端和javascriptserializer上的JSON.stringify。 – 2013-05-01 06:22:44
用「a b c ... z」替換所有奇特的unicode,然後再試一次。也就是說,將問題簡化爲*最小*測試案例 - 顯示序列錯誤*或* unicode編碼錯誤。 – user2246674 2013-05-01 06:33:04