WeLoveCSS Logo
Home Profile Members Search Rules Help New Posts



WeLoveCSS > PROGRAMMING LANGUAGES > Scripting and Server Side > calling an AJAX from a JS function

Reply
  Thread Tools Display Modes
Old 3rd March 09, 08:22 PM   #1
raphael75
WLC Member
 
Join Date: Sep 2008
Posts: 5
Default calling an AJAX from a JS function

I've encountered a wierd problem that I can't understand. Here's the scenario:

I have a page that displays a popup login box. It calls a function that uses document.createElement to create some divs. I am storing the contents of the innermost div in a file that I want to load dynamically through AJAX. Here's the scenario. I can't post the exact code because I'm doing this for work and we're not allowed to post our code:

web page calls JS function showloginbox()

showloginbox() creates the divs using document.createElement

showloginbox() then tries to open getloginboxcontents(), which only contains an AJAX call to an .ASP file that will return the contents to throw into the created element.

getloginboxcontents() calls the update function, showlogincontents(), which takes the request.responseText and puts it in the created element.

However, wherever I refer to the request object in showlogincontents(), I get an error saying "request is null".

If I change it and remove the showloginbox() and call getloginboxcontents() directly from the page, I don't get this error and the request processes as normal. This may be a little easier to understand:

Quote:
webpage: link to JS function showloginbox()

function showloginbox()
{
create some divs...

getloginboxcontents()
}

function getloginboxcontents()
{
//AJAX call to retrieve the contents of the div
createRequest() //creates a request variable
request.onreadystatechange = showloginbox
}

function showlogincontents()
{
if(request.readyState==4)
{
var resp=request.responseText
...
}
}
The "request is null" error always occurs on the first line in showlogincontents() that references "request". The error occurs as soon as the link is clicked on. Nothing in the first two functions processes (I verified this with Firebug), it immediately errors.

Can you call an AJAX function from another function? Or is something else going on here? Please help, thanks.
raphael75 is offline   Reply With Quote
Old 3rd March 09, 08:46 PM   #2
raphael75
WLC Member
 
Join Date: Sep 2008
Posts: 5
Default Re: calling an AJAX from a JS function

Nevermind! Had two functions with the same name. Holy ****, how frustrating!
raphael75 is offline   Reply With Quote
Reply


Thread Tools
Display Modes
Hybrid Mode Hybrid Mode

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:04 PM.



Home | Advertise | Contact Us | Top
Home | Advertise | Contact Us | Top

Copyright© 2006 WeLoveCSS.com. All Rights Reserved.
Powered by vBulletin Version 3.8.4 Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.