如何在经典 ASP 中返回 JSON 对象

How to return a JSON object in classic ASP(如何在经典 ASP 中返回 JSON 对象)
本文介绍了如何在经典 ASP 中返回 JSON 对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我想使用经典的 ASP 脚本返回一个 JSON 对象(它是 AJAX 请求的一部分).

I want to return a JSON object using a classic ASP script (it's part of an AJAX request).

如果我只是将回复发送为如下文本:

If I just send the reponse as text like:

response.write("{ query:'Li', suggestions:['Liberia','Libyan Arab Jamahiriya','Liechtenstein','Lithuania'], data:['LR','LY','LI','LT'] }")

这会起作用吗,还是我真的需要一个 JSON 库?

will this work, or do I actually need a JSON library?

我正在尝试在 http://www.devbridge.com/projects/autocomplete/jquery/#howto 工作.

I'm trying to get the autocomplete plugin at http://www.devbridge.com/projects/autocomplete/jquery/#howto to work.

javascript:

javascript:

 $(document).ready(function() {
    var a = $('#txtValue').autocomplete({ 
    serviceUrl:'script.asp',
    minChars:2, 
    maxHeight:400,
    width:300,
    zIndex: 9999,
    deferRequestBy: 0, //miliseconds
    onSelect: function(value, data){ alert('You selected: ' + value + ', ' + data); },
});

平均售价:

<% 
response.ContentType = "application/json"
response.write("{ query:'Li', suggestions:['Liberia','Libyan Arab Jamahiriya','Liechtenstein','Lithuania'], data:['LR','LY','LI','LT'] }") 
%>

自动完成功能不起作用.如果我使用像这样的本地查找数组,它会起作用查找:['一月','二月','三月','四月','五月']

Autocomplete is not working. It works if I use a local lookup array like lookup: ['January', 'February', 'March', 'April', 'May']

但是 ajax 有问题,这意味着它不能正确返回列表.

But there's something wrong with the ajax meaning it doesn't return the list properly.

推荐答案

好像是客户端解析错误.

It appears to be a parsing error on the client side.

我不认为这会有所作为,但看起来如果你引用所有内容,包括属性名称,它似乎可以工作.并使用双引号而不是单引号 - 这显然会有所作为.

I didn't think this would make a difference, but it looks like if you quote everything, including the property names, it seems to work. And use double-quotes instead of single quotes - that apparently is making a difference.

记得把你的双引号加倍(至少我认为你在 VBScript 中是这样做的——已经很久了).

Remember to double your double-quotes (at least I think that's how you do it in VBScript - been a long time).

所以:

<%
    Response.ContentType = "application/json"
    Response.Write("{ ""query"":""Li"", ""suggestions"":[""Liberia"",""Libyan Arab Jamahiriya"",""Liechtenstein"",""Lithuania""], ""data"":[""LR"",""LY"",""LI"",""LT""] }")
%>

这篇关于如何在经典 ASP 中返回 JSON 对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Show a progress bar for downloading files using XHR2/AJAX(显示使用 XHR2/AJAX 下载文件的进度条)
How can I open a JSON file in JavaScript without jQuery?(如何在没有 jQuery 的情况下在 JavaScript 中打开 JSON 文件?)
How do I get the HTTP status code with jQuery?(如何使用 jQuery 获取 HTTP 状态码?)
How to get response url in XMLHttpRequest?(如何在 XMLHttpRequest 中获取响应 url?)
WebKit quot;Refused to set unsafe header #39;content-length#39;quot;(WebKit “拒绝设置不安全的标头‘内容长度’)
$.ajax call working fine in IE8 and Doesn#39;t work in firefox and chrome browsers($.ajax 调用在 IE8 中运行良好,但在 Firefox 和 chrome 浏览器中不起作用)