Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-22-2010, 05:54 PM   PM User | #1
Dat
Regular Coder

 
Join Date: Oct 2007
Posts: 147
Thanks: 28
Thanked 0 Times in 0 Posts
Dat is an unknown quantity at this point
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..
Dat is offline   Reply With Quote
Old 01-22-2010, 10:53 PM   PM User | #2
Fumigator
UE Antagonizer


 
Fumigator's Avatar
 
Join Date: Dec 2005
Location: Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
Posts: 7,687
Thanks: 42
Thanked 637 Times in 625 Posts
Fumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of light
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.
__________________
Fumigator is offline   Reply With Quote
Old 01-23-2010, 01:07 AM   PM User | #3
bdl
Regular Coder

 
Join Date: Apr 2007
Location: Camarillo, CA US
Posts: 590
Thanks: 4
Thanked 83 Times in 82 Posts
bdl is an unknown quantity at this point
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.
bdl is offline   Reply With Quote
Old 01-23-2010, 01:27 AM   PM User | #4
Dat
Regular Coder

 
Join Date: Oct 2007
Posts: 147
Thanks: 28
Thanked 0 Times in 0 Posts
Dat is an unknown quantity at this point
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.
Dat is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:58 AM.


Advertisement
Log in to turn off these ads.