Skip to content Skip to sidebar Skip to footer

Get Value From Ajax Using Javascript And Asp

I am using this Ajax code. But I dont know how i will retrieve my value of value1 on my server-side asp using Javascript. On my serverside I want to have something like <% var

Solution 1:

Client-side Javascript can't query server-based databases for obvious reasons. Based on what you appear to be doing, I would suggest you code an ASP which performs the actual query using VBA / C# / whatever, and you can then parse the results in your client-side ajax call as normal.

Solution 2:

URL encode _data and nbquestions variables. Request.QueryString("param1") will decode them for you.

JavaScript URLEncode:

escape(_data);

Also you can use Server.URLEncode() methods from VB script.

Solution 3:

xmlHttp.send correctly writen

  • It doesn't check that you have a 200 status before trying to deal with the data.
  • It fails to encode the data to make sure it is URL safe

I would suggest using a library to handle XHR stuff, instead of reinventing the wheel. Microjs has a list of lots of small libraries if you aren't using one of the large ones (such as YUI or jQuery).

how do I get the values on the server-side using Javascript.

It is just query string data, so it will be in Request.QueryString.

Solution 4:

Whatever the server-side script outputs will be picked up by the AJAX request. So if the AJAX requests something, the server-side does the legwork and fetches the result from the database and then outputs it.

There are loads and loads of tutorials on how to do exactly this. Just ensure that you secure your script properly so that it's not open to abuse.

Solution 5:

you can make the asp page write the result as JSON format read in directly via XMLHttpRequest Object and later processing:

example of JSON

var myJSONObject = {"bindings": [
        {"ircEvent": "PRIVMSG", "method": "newURI", "regex": "^http://.*"},
        {"ircEvent": "PRIVMSG", "method": "deleteURI", "regex": "^delete.*"},
        {"ircEvent": "PRIVMSG", "method": "randomURI", "regex": "^random.*"}
    ]
};

then you can use native parsers in web browsers or eval() (NOT RECOMENDED, SERIOUSLY!!!) to parse the data written in your asp page and use it in your javascript client code.

More information about JSON basic info

JSON in browsers:

Post a Comment for "Get Value From Ajax Using Javascript And Asp"