Sending variable from AJAX page to ASP.net page not working?

  • Thread starter Thread starter SedativeChunk
  • Start date Start date
S

SedativeChunk

Guest
This should be a simple thing to fix for anyone good with AJAX/Javascript and ASP.net. I'm trying to send a variable to an ASP.net page named variable and return the value to the current page. Here's the Javascript code to look at:
var blog_id = 1;
var url = "comments.aspx?blog_id=" + escape(blog_id);
xmlHttp.open("GET", url, true);
xmlHttp.send(null);

On the ASP.net page, I have the following:
Dim blog_id As String = Request.QueryString(blog_id)
Response.Write("The blog ID is " & blog_id)

The ASP.net page properly communicates with the main page but does not print the blog_id. All I see is this:
The Blog ID is

The ASP.net page is not properly collecting the blog_id variable. Note, I've also tried without the escape function:
var url = "comments.aspx?blog_id=" + blog_id;

How can I pass this variable to the other page? What am I doing wrong? I've tested the blog_id variable with the alert function to check it's value and it's declaring right (it's actually be passed through a function) and it works right up until I try to pass it to that page!

Sorry for long description, I will pick best answer if it works!
Someone just answered about the quotes in the query string. I actually have the Request.QueryString("blog_id") in my original code, I forgot to put them on here. This is not the problem.
 
Dim blog_id As String = Request.QueryString("blog_id")

You need quotes around the query string variable. The way you had it, it was initializing blog_id to an empty string, then passing it into QueryString, which then returned nothing.

Edit: Your code looks very similar to what I've always done to do ajax requests in asp.net. I would have to see more of what you're doing to make further guesses. Have you tried ending the response with Response.End() ?
 
Back
Top