AJAX not working in my computer

Discussion in 'JavaScript' started by sugarland, Mar 24, 2009.

  1. #1
    I'm trying to write some ajax script, but even the simple one like below is not working in both IE and Firefox on my computer. What's wrong with the script? Or shall I change any settings for my browser?

     
    sugarland, Mar 24, 2009 IP
  2. lp1051

    lp1051 Well-Known Member

    Messages:
    163
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    108
    #2
    Hi,
    you need some sort of server on your local machine, to make it working. LAMP, XAMPP, whatever suits you...
     
    lp1051, Mar 24, 2009 IP
  3. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #3
    i'm not sure if this is the solution but i think it needs another closing } to close the function and </script> on the end
     
    camjohnson95, Mar 24, 2009 IP
  4. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #4
    you also need to call the function. The changes are in bold.
    
    <script language="javascript">
    var xmlHttp;
    function createAjax(){
    try{
    xmlHttp = new XMLHttpRequest(); //for Firefox, Safari, etc
    alert("Your browser is Firefox!");
    }catch(e){
    try{
    xmlHttp = new ActiveXObject("Msxml12.XMLHTTP"); //Internet Explorer 7.0
    alert("Your browser is IE7");
    }catch(e){
    try{
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); //IE4.0 -7.0
    alert("Your browser is IE5");
    }catch(e){
    alert("Your browser doesn't support Ajax!");
    return false;
    }
    }
    }
    [B]}
    createAjax();  
    </script>
    
    Code (markup):
    [/B]

    IE7 Does support XMLHTTPRequest, so IE7 will say it is firefox, you could change the order to put IE7 first and it would work, but it doesn't really matter, as long as it works.
     
    camjohnson95, Mar 24, 2009 IP
  5. JavaScriptBank.com

    JavaScriptBank.com Peon

    Messages:
    141
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    and all AJAX code must be excuted online (localhost or real host) you can not run at with local files
     
    JavaScriptBank.com, Mar 25, 2009 IP
  6. sugarland

    sugarland Member

    Messages:
    105
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    28
    #6
    Yes, after uploading the files to my server and testing it, it's working fine. Previously I just preview the html file on my computer.
     
    sugarland, Mar 25, 2009 IP
  7. Madhur Sharma

    Madhur Sharma Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I don't want to put files on local server. I need to make an ajax call to the local files.
    In Firefox everything works fine.
    In IE ajax call to html files works fine but it doesn't work when call is made to xml file.

    Can someone help me out?
     
    Madhur Sharma, Sep 7, 2010 IP