开发者

Javascript (jQuery) - Problem with $.post

So, for some reason my script refuses to work, although it seems to be correct.

I tried using $.ajax instead, but not working with that either. Any ideas what's gone wrong?

<script>
$(document).ready(function() {
     $('#saveForm .submit').click(function() {
      var _user = $('#saveForm .user');
       _userId = $('#saveForm .userId');
       _password = $('#saveForm .password');

      $('#saveForm').append('<p>Loading...</p>');

      $.post("ajax/fetchPhotos.php", {user:_user, userId:_userId, password:_password}, function(data) {
       alert(data);
    开发者_JAVA技巧  });

      return false;
     });
});
</script>

In ajax/fetchPhotos.php i have this:

<?php
set_time_limit(0);
session_start();
require_once("includes/functions.php");
require_once("includes/pclzip.lib.php");

/*
Huge block of code here (commented out for the moment)
*/
echo "wut?";

So, when clicking .submit, it should send a request to fetchPhotos.php with three params and then alert "wut?". Right now the page hangs in chrome.. nothing happens. In firefox the page just refreshes. I do get one error in the console, but i only see it for a split second as the page refreshes directly.

Thanks, Pete


you must use the .val() method to get the value of the inputs.

try this way:

<script>
$(document).ready(function() {

    $('#saveForm .submit').bind('click', function() {
        var 
            user = $('#saveForm .user').val(),
            id = $('#saveForm .userId').val(),
            password = $('#saveForm .password').val();

        $('#saveForm').append('<p>Loading...</p>');

        $.post("ajax/fetchPhotos.php", {user:user, userId:id, password:password}, function(data) { 
            alert(data);
        });

        return false;
    });
});
</script>


It seems syntax related problem and also try with absolute url or can do in this way

new Ajax.Request("ajax/fetchPhotos.php", {
            method: 'post',
            parameters: 'id='+id,
            onComplete: function(transport) {
            alert(transport.responseText);
            }
            });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜