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
//(javascript, ajax = xmlHttp)
if your response text is an array you can use this.
var myArray = eval(xmlHttp.responseText);
or if it is a just text you can use .
var value = xmlHttp.responseText
Another approach.This is just a template. If you use jquery, you can use this approach. i hope it solve your problem or give an idea.
html part:
<div id="willupdate"></div>
<div id="willupdate2"></div>
JQuery part:
$(document).ready(function() {
getValue("serverurl",updateName)
getValue("serverurl",updateSurName)
});
function updateName(name){
$("#willupdate").text(name)
}
function updateSurName(name){
$("#willupdate2").text(name)
}
function updateSurName(name){
$("#willupdate").text(name)
}
function getValue(url,opt_onRecieved){
if( !url || url == ""){
alert("request url error");
return;
}
$.ajax({
type:"POST",
url: url,
dataType:"json",
success: function(data){
opt_onRecieved(data);
}
});
}
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.
xmlHttp.send correctly writen
200
status before trying to deal with the data.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
.