DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Javascript not working (ajax with asp)

  1. #1
    Join Date
    Mar 2007
    Posts
    1

    Javascript not working (ajax with asp)

    Hello, I seem to have a rather strange error.

    JavaScript:
    // JScript File

    var objXMLHttp

    function subscribe(str) {
    var regEx = /^[\w\.\+-]{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]{2,6}$/;
    if (!regEx.test(str)) {
    document.getElementById('div').innerHTML = 'Invalid email';
    alert('Invalid email!');
    return false;
    }

    objXMLHttp=createXmlHttpObject()

    if (objXMLHttp==null) {
    alert ('Your browser does not support the XMLHttpRequest object!');
    return;
    }

    var url='subscribe.aspx?eml=' + str + '&sid=' + Math.random();
    objXMLHttp.onreadystatechange = stateChanged;
    objXMLHttp.open('GET',url,true); // GET method
    objXMLHttp.send(null); // always use null for GET method
    }

    function createXmlHttpObject() {
    var req = null;
    try {
    req = new XMLHttpRequest(); //ie7, ff, safari
    }
    catch (e) {
    try {
    req = new ActiveXObject("Msxml2.XMLHTTP"); //later ie
    }
    catch (e) {
    try {
    req = new ActiveXObject("Microsoft.XMLHTTP") // earlier ie
    }
    catch (e) {
    // could not create XMLHttpRequest object
    return false;
    }
    }
    }
    return req;
    }

    function stateChanged()
    {
    if (objXMLHttp.readyState == 0) {
    document.getElementById("div").innerHTML = "Processing..."; //uninitialized
    }
    else if(objXMLHttp.readyState == 1) {
    document.getElementById("div").innerHTML = "Processing..."; //loading
    }
    else if(objXMLHttp.readyState == 2) {
    document.getElementById("div").innerHTML = "Processing..."; //loaded
    }
    else if(objXMLHttp.readyState == 3) {
    document.getElementById("div").innerHTML = "Processing..."; //interactive
    }
    else if (objXMLHttp.readyState == 4 || objXMLHttp.readyState == "complete") {
    document.getElementById("div").innerHTML= objXMLHttp.responseText;
    }
    }

    The file subscribe.aspx has a page_load method which just do Response.Write("Test");

    I get an error when trying to get the response (objXMLHttp.responseText)

    If I replace this:

    document.getElementById("div").innerHTML= objXMLHttp.responseText;


    with this:

    document.getElementById("div").innerHTML= "Test";

    It works. Anyone know why I can't get the response message that subscribe.aspx generates?

  2. #2
    Join Date
    Jun 2008
    Posts
    1
    Hi,

    Did you get the solution to this problem ? I am too having the similar problems in one of my Perl script.

    Thanks
    Shyam

Similar Threads

  1. Replies: 0
    Last Post: 02-22-2002, 08:44 AM
  2. ASP within Javascript?
    By Botard in forum ASP.NET
    Replies: 2
    Last Post: 12-05-2001, 05:29 PM
  3. Replies: 1
    Last Post: 11-20-2001, 04:47 AM
  4. ASP pages not working on Win NT4 & IIS
    By hash in forum ASP.NET
    Replies: 1
    Last Post: 10-01-2001, 11:46 PM
  5. asp page not working
    By Charity in forum ASP.NET
    Replies: 3
    Last Post: 01-17-2001, 11:52 AM

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
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

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