DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 1 of 1

Thread: using an AJAX function to return a value

  1. #1
    Join Date
    Jun 2007

    Question using an AJAX function to return a value - HELP!

    I will start with the disclaimer that I am still quite new to AJAX and JavaScript and I'm sure the answer will turn out to be obvious but its been driving me mad.
    I am designing a system that uses a javascript/html front end with the help of ajax to populate various fields from an sql backend. I want to call a function called ajax() with details of the ajax request as paramaters and use the returned xml object for processing. As the response of the ajax request is handled within the onreadystatechange function I am unable to simply say 'return xml' as this function is called after the ajax() function has exited. I want to return the xml object to code that called the ajax function in the first place. I have a feeling I can use intervals within my ajax() function to keep testing for when the xml object has been populated but am still having trouble. (IE has been telling me the script is unresponsive after about 5 seconds of this despite the request only taking 1 second to complete when i remove the wait-and-test loop). To make it clearer here is an example of what should happen.

    1) code: document.getElementById("Field").value=ajax("getFieldValue",id).value;
    2) In the ajax() function the xmlhttp.onreadystatechange() event function is set with contents that put the response into my xml object.
    3) ajax() function begins to wait for the server response by testing request.readyState.
    4) The onreadystatechange() works its magic and populates my global xml object with the data from the server.
    5) ajax() function returns the xml object (or filtered data from the object depending on the particular type of ajax request being called) to the code in part 1 and the xml.value is entered into 'Field'.

    This is just an example of what I want it to do as the whole idea is that I can use the ajax function for many dirrerent instances of data retrival rather than hardcode lines into the ajax function telling it to change specific DOM elements.

    Hope that makes a bit of sense and I hope someone can help.

    Last edited by k285715; 06-22-2007 at 02:42 AM.

Similar Threads

  1. Replies: 27
    Last Post: 02-11-2016, 06:29 AM
  2. Replies: 0
    Last Post: 05-22-2007, 02:19 AM
  3. Replies: 1
    Last Post: 04-25-2007, 11:39 AM
  4. please help me
    By idea2 in forum .NET
    Replies: 7
    Last Post: 02-22-2007, 08:40 PM
  5. Packed Data(Comp-3, etc)
    By Marcos in forum VB Classic
    Replies: 3
    Last Post: 01-25-2006, 12:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center