PDA

View Full Version : asp & javascript - I'm lost!


mljonzs
03-06-2006, 01:27 PM
:(
I could really use some big help here. Let me see if I can explain what I am trying to do. I need to add some logic to an existing asp/javascript based web application. At the point I need to do this, I am knee deep in a javascript file and I need to prompt the user to enter a value that I can then use to go to an asp page to run on the server to pull more data from the database before continuing. I don't know how to best accomplish this since like I said, I'm inside the javascript file which is basically already running inside of a web page form. I can use the alert function and pick up the value from the user but I can't figure out how to successfully jump to my asp page that is coded to do the DB pull and then come back to that javascript file again to finish up processing. I'm sure my lack of knowledge of complete understanding of web page flow is part of my problem (I'm more used to non-web programming).

If anyone can understand what I'm trying to do and offer some help I would be very greatful! I have been searching the web for a couple of days now and I can't seem to get this done right and don't know where to turn.

Thanks!
mlj

_Aerospace_Eng_
03-07-2006, 02:14 PM
Look in to AJAX. AJAX can interact with the server to an extent. I have never really worked with AJAX before though.

napster.it
03-30-2006, 02:02 AM
Hi michelle,
i guess u need to make an asynchronous callback to the server using either callback feature in ASP.NET 2.0 or by using some third party callback controls( though i wud recommend d 1st 1).
using callback u can also pass parameters but it can only be accessed at server side as a string.
all documentation regarding making a callback can be found in MSDN itself, just search by the keyword "callback". if u still need some sample, just tell me, i ll post it here.
hope this helps

RysChwith
03-30-2006, 09:22 AM
I've done a little bit with AJAX, although not a whole lot. A couple of articles I found helpful:

http://developer.apple.com/internet/webcontent/xmlhttpreq.html
http://jibbering.com/2002/4/httprequest.html

Both of them describe the XML HTTPRequest object, which can be used by JavaScript to request pages and data from the server.

Rys

bendman
03-30-2006, 01:29 PM
I'm an AJAX developer but I've never used it with ASP before. It just works with the output of a file, so just get your ASP to output the string you want. To pass items to the server I've always used GET, with a modified url, but I don't know how ASP handles GET passes. Because AJAX is asynchronous it's impossible to create one function you can call which simply returns a value, you need to have it go to another function which does what you need with the new data once it's loaded. To use the function I normally use, just do "useExternalData('url_of_your_asp_file', variable_to_pass_to_asp)" Here's the function:function useExternalData(dataSrc, passedValue) {
if (window.ActiveXObject){
XMLHttpObj = new ActiveXObject("Microsoft.XMLHTTP");
} else if (window.XMLHttpRequest) {
XMLHttpObj = new XMLHttpRequest();
}
if (XMLHttpObj) {
XMLHttpObj.onreadystatechange = function() {
if (XMLHttpObj.readyState == 4) {
try {
if (XMLHttpObj.status == 200) {
doSomethingWith(XMLHttpObj.responseText);
} else {
var errorMsg = '\'' + XMLHttpObj.status + ' Error\' for file ' + windowURL;
alert(errorMsg);
}
} catch(e) {
}
}
};
var dataSrcUrl = dataSrc + '?clientVar=' + passedValue;
XMLHttpObj.open("GET", dataSrc, true);
XMLHttpObj.send(null);
}
}Just change the function "doSomethingWith(XMLHttpObj.responseText)" to whatever you want done to the data. XMLHttpObj.responseText is the output, as a string, of the file your getting.

in your ASP, the value of clientVar (however you call it with GET) is the data passed from the clients computer.

edit: changed the function to accept variables passed to serverside