Link to home
Start Free TrialLog in
Avatar of JElster
JElsterFlag for United States of America

asked on

REST service in Classic ASP ?

How can I create a rest service in old classic asp. Or create asp page that will serve or provide data that can be used
with JQUERY  to read the data.   Use an ASP page as the DAL and have have HTML page and JQuery read from the asp
page and populate a grid.
Avatar of Big Monty
Big Monty
Flag of United States of America image

have a go at this:

<% 
if Request("mode") = "1" then    '-- ajax call to REST service
dim objXMLHTTP, results
set objXMLHTTP = Server.CreateObject("Microsoft.XMLHTTP")
objXMLHTTP.Open "GET", "http://www.website.com", false 
objXMLHTTP.SetRequestHeader "Content-type", "text/html" 
objXMLHTTP.Send

results = objXMLHTTP.ResponseText
%> 

Open in new window


with this bit of code, you now have all of the data in a variable called results.

all you have to do is make an ajax call to that bit of code:

$(document).ready(function(){

    $('#btnGetData').bind('click', function (event) {
		 $.ajax({
			 type: "POST",
			 url: "page.asp",
			 data: "mode=1,
			 cache: false,
			 success: function(html) {	
                               //-- parse your data here and put into the grid. if you expect the data back in JSON format, you can use the jquery parseJSON() function
                         }
		 });
    });
});

Open in new window


what kind of grid are you using and what format do you expect the data returned as?
Avatar of JElster

ASKER

I need to query a DB.. I guess using
Set connection = Server.CreateObject("ADODB.Connection")

and get a dataset.

Then how do I have jquery read / parse the dataset?

Using Kendo UI grid or someother Jquery grid.. not sure.

thx
are you trying to build a REST service or consume one?
ASKER CERTIFIED SOLUTION
Avatar of Big Monty
Big Monty
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JElster

ASKER

Thanks.. it is possible to include all the code in one ASP file?  Or do I need a separate 'userSearch.asp' and another HTML or ASP page?
You will need 2 pages and it looks like Big Monty is leading you to making your ajax page http:Q_28480375.html#a40209467

Then you will need  a main page as well.
Avatar of JElster

ASKER

Any idea how I can add more than one query on a page..

<!--#include virtual = "/includes/plugins/aspJSON/JSON_2.0.4.asp"-->
<!--#include virtual = "/includes/plugins/aspJSON/JSON_UTIL_0.1.1.asp"-->
<%
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open connectionString

sql = "select * from table"
QueryToJSON( conn, sql ).Flush

if conn.State <> 0 then conn.Close
set conn = nothing
%>
sql = "SELECT * FROM table WHERE some_field = 'foo'"

or

foo = request.querystring("bar")
sql = "SELECT * FROM table WHERE some_field = '"&foo&"'"
Avatar of JElster

ASKER

How can I have more than of these on  page...

sql = "select * from Customers"
 QueryToJSON( conn, sql ).Flush


sql = "select * from Orders"
 QueryToJSON( conn, sql ).Flush
If request.querystring("type")="customers" then

             sql = "select * from Customers"
             else
             sql = "select * from Orders"
end if

QueryToJSON( conn, sql ).Flush

Open in new window