1

我有几个不同的 html 字符串通过 ASP.NET 写入 DOM 并存储在会话中。这些字符串包含 html 实体,如“  ”和“ −”。

我使用 .html() 来获取由 asp 打印的 html,然后使用 AJAX 在后台将 html 发布到另一个 asp 文档,在该文档中我尝试将会话中的 html 与 JS 在编写后抓取的 html 进行比较。

我的问题是,当它们进行比较时,来自 JS 的字符串将显示为“- blah”,而 asp 会话显然显示为“ − blah”。我怎样才能让 JS 匹配 asp 或其他方式?

我尝试使用 Server.HTMLEncode(session("name")) 来获取大多数字符串匹配,但将 ' &' 上的 ' −' 更改为 ' −'。

任何帮助将不胜感激!提前致谢。

这是显示代码的小提琴。JS小提琴不运行asp。 http://jsfiddle.net/JnKaT/3/

jQuery

$('#submit').click(function(st) {       

    $('input[type=radio]:checked').each(function(rc) {
        var userAns =  $(this).parent().next('td').html();

        console.log(userAns);

        $.ajax({
            cache: false,
            type: "POST",
            data: userAns,
            url: "/beta/includes/answerCheck.asp",
            success: function(msg) {
                console.log(msg+" ");
            },
            error: function(err) {
                console.log(err.responseText);                
            }
        });

    });

    return false;
    st.preventDefault();
});​

ASP

<!-- creating dynamic session name for html string -->
<%
for j = 1 to itemCount
sessionName = "correctAns"&(j)
session(sessionName) = session("d1")

response.write("<div class='qans'>"&session(sessionName)&"</div>")

next
%>


<!-- asp used by AJAX to compare the session to the js string -->


<%
userAns = request.form()


    corSessionName = "correctAns"&(qn)
    userSessionName = "userAns"&(qn)

        if userAns = session(corSessionName) then
            response.write("correct! ")

            response.write("ASP:"&session(corSessionName))
            response.write(" ,user:"&userAns)
        end if

        if userAns <> session(corSessionName) then 
            session(userSessionName) = userAns

            response.write("incorrect :( ")

            response.write("ASP:"&session(corSessionName))
            response.write(" ,user:"&userAns)
        end if  
%>

按钮

<button id="submit" name="Check my answers!!" align="left">Check my answers!</button>​
4

1 回答 1

0

正如 Sime Vidas 所说,我无法从 DOM 中获取 HTML 实体,因此为了解决我的问题,我在 asp 会话中解码了 html 字符串以使其与 DOM 上的 html 匹配

Dim I
tempAns = Replace(tempAns, "&quot;", Chr(34))
tempAns = Replace(tempAns, "&lt;"  , Chr(60))
tempAns = Replace(tempAns, "&gt;"  , Chr(62))
tempAns = Replace(tempAns, "&amp;" , Chr(38))
tempAns = Replace(tempAns, "&nbsp;", " ")

For I = 1 to 255
    tempAns = Replace(tempAns, "&#" & I & ";", Chr(I))
Next

session(sessionName) = tempAns
于 2012-12-09T21:10:19.473 回答