Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Dat
    Dat is offline
    Regular Coder
    Join Date
    Oct 2007
    Posts
    147
    Thanks
    28
    Thanked 0 Times in 0 Posts

    Ajax using $.ajax

    I can't get the ajax to work.

    I am very new to ajax and javascript, I usually work with PHP.

    Code:
    <script>
        $(document).ready(function(){
    
            $("#list_status select").change(function () {
                var str = "";
                $("select option:selected").each(function () {
                    str = $(this).text();
                    data = $(this).siblings("form").serialize();
                    $.ajax({
                       type: "POST",
                       url: "list.php",
                       data: data,
                       success: function(msg){
                         alert( "Your status updated as: " + msg );
                       }
                     });
                });
    
                $("#list_status").find("span").text(data);
            })
            .trigger('change');
    
        });
    </script>
        <form style="padding:0px;" class="form" method="post" enctype="multipart/form-data" action="/list.php?type=<?php echo $type; ?>&id=<?php echo $entry_id; ?>">
            <fieldset>
                <ul>
                    <li id="list_status">
                        <select name="list_status">
                            <option value="0" selected>Select your status</option>
                            <option value="1">Completed</option>
                            <option value="2">Watching</option>
                            <option value="3">Dropped</option>
                        </select>
                        <span></span>
                    </li>
                    <li><input class="submit" type="submit" name="submit" value="Submit"/></li>
                </ul>
            </fieldset>
        </form>
    Last edited by Dat; 01-22-2010 at 05:58 PM.

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    You've got a lot of spots in that code that could be failing-- why do you think it's the ajax spot? Also, if you're not already, install the firebug add-on in Firefox and check out the ajax communication using it. It gives you a lot of good info on the transaction.

  • #3
    bdl
    bdl is offline
    Regular Coder
    Join Date
    Apr 2007
    Location
    Camarillo, CA US
    Posts
    590
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Aside from what Fumigator mentioned, have you reviewed the straight markup that PHP is producing from this script? Make sure your entity names / values are correct. Firebug is going to be a huge help overall, make sure you get that installed and learned to use it.

    Please also bear in mind that "ajax doesn't work" is an extremely vague, unhelpful comment. The more thought you put into your post, the more thought we put into it.

  • #4
    Dat
    Dat is offline
    Regular Coder
    Join Date
    Oct 2007
    Posts
    147
    Thanks
    28
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by bdl View Post
    Aside from what Fumigator mentioned, have you reviewed the straight markup that PHP is producing from this script? Make sure your entity names / values are correct. Firebug is going to be a huge help overall, make sure you get that installed and learned to use it.

    Please also bear in mind that "ajax doesn't work" is an extremely vague, unhelpful comment. The more thought you put into your post, the more thought we put into it.
    When I remove the ajax part of the javascipt the code works and the status gets outputted but when i include the ajax back into the code the status doesn't get outputted anymore.


  •  

    Posting Permissions

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