Am having a issue with ajax form for some reason it dont always work post the correct data am having to click the image 3 or 4 times before it will load the portrait and gallery numbers.

can anyone help me out ?

    **       Form.php**
            <script>
            $(document).ready(function() {
                $('.ajaxform').click(function() 
                {
                   var avatar = $(this).data("portrait");
                   var avatardir = $(this).data("gallery");

                   $.post('update.php', {avatar : avatar, avatardir : avatardir}, function(data, status) 
                   {
                     $("#info").html(data);
                     alert("Data: " + data + "\nStatus: " + status);
                   }); 
                });
            });
            </script>

            <div id="info">
              <input name="updateMyPortrait" type="hidden" id="updateMyPortrait" value="1" />
              <input name="avatardir" type="hidden" id="avatardir" value="<?php echo $_POST['avatardir']; ?>" />
              <input name="avatar" type="hidden" id="avatar" value="<?php echo $_POST['avatar']; ?>" />
            </div>

 **       input image for clicking on:**
           <td><div><input class=\"ajaxform\" data-portrait=\"#{$str3}\" data-gallery=\"#{$avatarimg}\" type=\"image\" src=\"{$files[$pos]}\" width=\"88\" height=\"88\" border=\"1\"></div></td>

  **        update.php:**
            <input name="avatardir" type="hidden" id="avatardir" value="<?php echo $_POST['avatardir']; ?>" />
            <input name="avatar" type="hidden" id="avatar" value="<?php echo $_POST['avatar']; ?>" />

Thanks.

How big is the image file? If it is quite big (even 1 MB), it could take sometimes to load. Ajax is supposed to be for small data transaction so that the client doesn't need to reload the whole page...

Member Avatar for diafol

You could show a loading animation (simple animated gif) on load and hide on completion. In the same way you could set a visual 'disabled' e.g. greyed-out overlay) on the upload trigger.

its not loading image only getting the image location basicly gallery ID and Picture ID but it dont seam to be working correctly not always adding the selected ids.

Member Avatar for diafol

WHy is all that html got escape chars all over the place? Are you spitting that out in PHP?!

yes all within side of php script, that is aecho "<td><div><input class=\"ajaxform\" data-portrait=\"#{$str3}\" data-gallery=\"#{$avatarimg}\" type=\"image\" src=\"{$files[$pos]}\" width=\"88\" height=\"88\" border=\"1\"></div></td>";

thats reason

Member Avatar for diafol

Oh dear. That.s why it didn.t make any sense. So what is the ajax supposed to do? Just replace numbers in input controls?

basicly when you click on a image data-portrait=\"#{$str3}\" AND data-gallery=\"#{$avatarimg}\" will get the image id(portrait) and folder id(gallery) and then post them so I can submit then to database

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.