Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

REST service in Classic ASP ?

Posted on 2014-07-21
11
Medium Priority
?
2,487 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
[X]
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
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 33

Accepted Solution

by:
Big Monty earned 1600 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 53

Assisted Solution

by:Scott Fell, EE MVE
Scott Fell,  EE MVE earned 400 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 53

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 53

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 53

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

719 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