如何在传统的ASP返回一个JSON对象 [英] How to return a JSON object in classic ASP

查看:126
本文介绍了如何在传统的ASP返回一个JSON对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要回使用传统的ASP脚本(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?

编辑:我试图让自动完成插件的<一个href="http://www.devbridge.com/projects/autocomplete/jquery/#howto">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); },
});

ASP:

<% 
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']

但有一些错误的阿贾克斯这意味着它不会返回列表中正确。

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对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆