Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

REST service in Classic ASP ?

Posted on 2014-07-21
11
1,993 Views
Last Modified: 2014-07-21
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.
0
Comment
Question by:JElster
  • 4
  • 4
  • 3
11 Comments
 
LVL 33

Expert Comment

by:Big Monty
ID: 40209406
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?
0
 
LVL 1

Author Comment

by:JElster
ID: 40209417
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
0
 
LVL 33

Expert Comment

by:Big Monty
ID: 40209425
are you trying to build a REST service or consume one?
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 33

Accepted Solution

by:
Big Monty earned 400 total points
ID: 40209467
if you're trying to pull data out of database to put into a grid, i would skip the "REST service" part of it for now, and just get the basics down. first thing I would do is familiarize yourself with aspJSON, a library that'll allow you easily build and manipulate json data in classic asp. you can find the component here:

https://code.google.com/p/aspjson/

second, choose which jquery you want to use. I prefer jqGrid, mainly because it's simple and easy to set up.

once you have downloaded the files and put them in your site, it's easy to code the html:

            <div id="gridContainer" align="center">
                <table id="users"></table>
            </div>

Open in new window


that's it! of course, you need to reference all of the files that are needed by the grid as well.

to initialize the grid and load it with data, you can use the following as a guide to get you going in the right direction:

$(document).ready(function () {
    $("#users").jqGrid({
        datatype: "json",
        url: "/webServices/userSearch.asp",
        gridview: true,
        emptyrecords: "no users to view",
        colNames: ['column1', 'column2', 'column3', 'column4'],
    });

Open in new window


what this code does is make a call to a page and if it receives data in a json format, it'll display it in the grid.

your userSearch.asp page (in this example) will look like this:

<!--#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
%>

Open in new window

this code, using the aspJSON component, will query the database and display the results in a json format. The QueryToJSON() function is actually writing out the data to the screen, and since it's an ajax call, it spits out the data back to the ajax call, which then translates it to the grid
0
 
LVL 52

Assisted Solution

by:Scott Fell, EE MVE
Scott Fell,  EE MVE earned 100 total points
ID: 40209587
no points

fyi, a small portion of kendo is not open source and the grid is one of those items and only available if you pay.  For a grid, you can use www.datatables.net.  There is a built in ajax function  http://www.datatables.net/examples/data_sources/ajax.html

Looking at that example, you just need basic html like this
<table id="example" class="display" cellspacing="0" width="100%">
        <thead>
            <tr>
                <th>Name</th>
                <th>Position</th>
                <th>Office</th>
                <th>Extn.</th>
                <th>Start date</th>
                <th>Salary</th>
            </tr>
        </thead>
 
        <tfoot>
            <tr>
                <th>Name</th>
                <th>Position</th>
                <th>Office</th>
                <th>Extn.</th>
                <th>Start date</th>
                <th>Salary</th>
            </tr>
        </tfoot>
    </table>

Open in new window


The asptojson code that monty is leading you to will use the json objects sample http://www.datatables.net/examples/ajax/objects.html rather than the default array sample.  The key is to check your output in a json linter to make sure it is valid http://jsonlint.com/
0
 
LVL 1

Author Comment

by:JElster
ID: 40209593
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?
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 40209636
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.
0
 
LVL 1

Author Comment

by:JElster
ID: 40209934
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
%>
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 40209979
sql = "SELECT * FROM table WHERE some_field = 'foo'"

or

foo = request.querystring("bar")
sql = "SELECT * FROM table WHERE some_field = '"&foo&"'"
0
 
LVL 1

Author Comment

by:JElster
ID: 40209984
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
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 40210015
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

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question