使用以下代码:
<script language="javascript">
<![CDATA[
// content of your Javascript goes here
$(document).ready(function () {
$("#txtModel").autocomplete({
source: function(request, response) {
$.ajax({url: "searchIModel.asp", dataType: "json", data: {term: request.term, itembrand: $("#txtBrand").val(), test: 85},
success: function(data) { response(data); }
});
},
minLength:1});
});
]]>
</script>
调用经典的 ASP 并返回 JSON 数据,但未过滤双引号和与号 (&) 并呈现缩短的返回值。有什么解决办法吗?
这是经典的 ASP 页面。这里实际上是接收 JSON 数据。
<%
Function UpCase(StringtoBeUppercase)
UpCase = UCase(Trim(StringtoBeUppercase))
End Function
'start initializing popup window for models
Dim iBrand, iModel, mdlResult, stat, ctr
usrID = session("userSession")
action = trim(request.QueryString("test"))
if action = "85" then
iBrand = UpCase(request.QueryString("itembrand"))
iModel = UpCase(request.QueryString("term"))
if trim(iModel) <> "" then
stat = skuObj.searchIModel(iBrand,iModel,iDesc,usrID)
end if
'if there are matches to the query; extract 10 recordset more
if trim(stat) ="00" then
'generate a JSON-type string result
mdlResult = "[{""id"":""" & "model0" & """,""value"":""" & trim(iModel) & """},"
for ctr = 1 to 10
stat = skuObj.searchIModel(iBrand,iModel,iDesc,usrID)
if stat <> "00" then
exit for
else
mdlResult = mdlResult & "{""id"":""" & "model" & CStr(ctr) & """,""value"":""" & trim(iModel) & """},"
end if
next
mdlResult=left(mdlResult,len(mdlResult)-1)
mdlResult = mdlResult & "]"
response.write(mdlResult)
end if
end if
%>
这里返回的是一些数据,比如模型;
索尼克
索尼EBC
SONY & ABC --> 这需要解析 (&)
新聚科
SYNJUCO "BELL" --> 这需要解析 ("")
天光
有什么解决办法吗?