Question: When sending a request using ajax in the page, if url compared with Chinese garbled
Solution: url to be encoded at encode transmission request, then the time decoding decode the received background
Paste the code below:
page:
$(function () { var img$ = $("img"); var url = { url1:img$.eq(0).attr("src"), url2:img$.eq(1).attr("src") }; $("#btnCompare").click(function () { $.ajax({ url: encodeURI('/Home/ComparePhoto?url1='+url.url1+"&url2="+url.url2), dataType: ' text ' , type: ' the POST ' , Success: function (Data) { IF (Data> . 5 ) { Alert (Data + " : Image is not very similar to " ); } the else { Alert (Data + " : very similar images " ); } } }); }); })
//后台:
public ActionResult ComparePhoto(string url1, string url2) { string s1 = Server.MapPath("/") + Server.UrlDecode(url1); string s2 = Server.MapPath("/") + Server.UrlDecode(url2); SimilarPhoto image1 = new SimilarPhoto(s1); SimilarPhoto image2 = new SimilarPhoto(s2); string hash1 = image1.GetHash(); string hash2 = image2.GetHash(); int count = SimilarPhoto.CalcSimilarDegree(hash1, hash2); return Content(count + ""); }