How to return a JSON object in classic ASP

前端 未结 3 744
慢半拍i
慢半拍i 2020-12-11 01:10

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(\"         


        
3条回答
  •  难免孤独
    2020-12-11 02:06

    I got it to work with the code below.... After doubling the quotes and putting in the query string

    currQuery= request.querystring("query")
    response.expires=-1
    Dim rsMain,sqlMain,rettxt,JobOpenToArr
    set rsMain= Server.CreateObject("ADODB.Recordset")
    rsMain.CursorLocation = adUseClient
    sqlMain = "select JobOpenTo FROM Jobs WHERE JobOpenTo LIKE '%"&currQuery & "%' group by JobOpenTo order by JobOpenTo" 
    rsMain.Open sqlMain, Session("XXX_CMS")
    if Not rsMain.Eof  Then   
                  '## build the string
           rettxt = "{query:""" & currQuery & """, suggestions:["
    
         JobOpenToArr = rsMain.getRows()     
         For i = 0 to UBound(JobOpenToArr,2)
    
           rettxt = rettxt & """" & JobOpenToArr(0,i) & ""","
    
         Next    
         '##knock off trailing comma
         rettxt = left(rettxt,len(rettxt)-1)
         rettxt = rettxt & "]}"
         Response.Write rettxt 
    

提交回复
热议问题