SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: jQuery ajax

  1. #1
    SitePoint Wizard Zaggs's Avatar
    Join Date
    Feb 2005
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    jQuery ajax

    Hi Guys!

    I'm trying to get jQuery to send values to a PHP script using Ajax. Here's the code I have so far, but it doesn't seem to alert me with any data. I know the PHP scripts works, so just need to get this part working. Any ideas?

    Code JavaScript:
    <script>
    $(document).ready(function() {
    	$("#location_ajax").keydown(function(event){
    		$.get("ajax/locations.php", { input: "chigwell" },function(data){ alert("Data Loaded: " + data); });
    	});
    });
    </script>

  2. #2
    Non-Member
    Join Date
    Apr 2011
    Location
    no fixed address
    Posts
    851
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It might be easier to debug it if you ditch the jquery. Not sure why you want to do this using jquery when you can most likely do it with less code using plain javascript.

    You could just create an ajax object and then use its responseText property to monitor what is going on in your php script and to check what it is returning. Using just plain javascript, when the data is loaded in the server you would send back a message like "success" via the responseText after which the alert() can be fired in the onreadystatechange handler.

  3. #3
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,707
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by Zaggs View Post
    I'm trying to get jQuery to send values to a PHP script using Ajax. Here's the code I have so far, but it doesn't seem to alert me with any data. I know the PHP scripts works, so just need to get this part working. Any ideas?
    Your code works for me, so there's something else that's going wrong.

    If you provide a link to a test page that demonstrates the problem, we can use development tools to find out exactly where the problem is occurring, and get closer to a viable solution for you.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •