1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Simple AJAX problem.

Discussion in 'JavaScript' started by gch5185, Nov 8, 2010.

  1. #1
    Sorry but I really have to ask. I have been trying this AJAX for hours!

    Please go to this link..
    http://www.w3schools.com/ajax/tryit.asp?filename=tryajax_first

    I copied all the codes on the left hand side and saved it into a new html file called a.html. Then I opened it with my Chrome/Firefox. I can see a line of text and a button but when I click on the button, it does nothing. Please tell me why. :(
     
    gch5185, Nov 8, 2010 IP
  2. wing

    wing Active Member

    Messages:
    210
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    58
    #2
    You need to run it on a webserver?
    Or you are trying to fetch data from a file that is not there (ajax_info.txt) ?
     
    wing, Nov 8, 2010 IP
  3. gch5185

    gch5185 Peon

    Messages:
    114
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I need the AJAX in my webserver but now I'm trying it with my pc alone first. I try to fetch the text file which is exist. Do I have to put them into a server to work?
     
    gch5185, Nov 8, 2010 IP
  4. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #4
    Yeah unless you have a webserver installed on your pc.
     
    camjohnson95, Nov 9, 2010 IP
  5. gch5185

    gch5185 Peon

    Messages:
    114
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    This is my code. I tried it in WAMP and everything is working fine. It is able for me to fetch the like.php and execute properly.

    After I have uploaded this code to my webserver and I tried to do the same thing, it is not working. When I click on the image, it gives me no response. Meaning to say that, there must be something wrong with my ajax and it does not fetch the like.php file.
     
    Last edited: Nov 9, 2010
    gch5185, Nov 9, 2010 IP
  6. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #6
    Did you also upload the 'like.php' file?
     
    camjohnson95, Nov 9, 2010 IP
  7. gch5185

    gch5185 Peon

    Messages:
    114
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Yes I did. I tried to run this in WAMP server and it works fine but when I try to run it in webserver, it is not working. FYI, all files in webserver and in WAMP is exactly the same.

    Btw.. The file contains the JavaScript and HTML above is a php file. Will this affect anything I wonder?
     
    gch5185, Nov 9, 2010 IP
  8. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #8
    I really can't see a problem with the javascript, although maybe im missing something...
    try loading like.php with some random args within your browser and see what it returns.. maybe the problem is with the php...
     
    camjohnson95, Nov 9, 2010 IP
  9. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #9
    or maybe your $id var is not returning what you expected... try displaying that also just to eliminate that as a problem...
     
    camjohnson95, Nov 9, 2010 IP
  10. gch5185

    gch5185 Peon

    Messages:
    114
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Everything is working fine except the javascript, this is what I'm suspecting. The like.php file loads fine and the $id returns a value too.

    [​IMG]

    I'm not sure what is going on here.. Seriously I tried it WAMP, it works great but not in here. :(
     
    gch5185, Nov 9, 2010 IP
  11. gch5185

    gch5185 Peon

    Messages:
    114
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #11
    This is the source code ..

     
    Last edited: Nov 9, 2010
    gch5185, Nov 9, 2010 IP
  12. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #12
    <img onclick="likepage(<?php echo $id; ?>,1)"

    ... where is the 'likepage' function?
     
    camjohnson95, Nov 9, 2010 IP
  13. gch5185

    gch5185 Peon

    Messages:
    114
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #13
    Sorry for the confusion caused. Initially the function name is called likepage() and I copied the wrong file, very sorry.
     
    gch5185, Nov 9, 2010 IP
  14. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #14
    There is nothing wrong with your javascript, it should work fine. The problem must be occurring somewhere with the file that it is trying to retrieve.
     
    camjohnson95, Nov 9, 2010 IP