1

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);
      });

      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

3
  • What does your markup look like? Commented Dec 3, 2010 at 13:43
  • In Firefox, have you looked at the Error Console? This is inside the Tools menu. Information inside the Error Console does not vanish unless you clear it manually. Also, if you look at the logs for the web-server where the PHP script is hosted, do you see any requests made to your script? Also, the HttpFox extension on Firefox will help you track requests and responses. Commented Dec 3, 2010 at 13:45
  • @Nick, i don't see why you would need the markup. It's simple though, i have a form with three inputs whith classes. @Ayaz, i didn't know about that! Thanks. This is what i see in the error console: heypasteit.com/clip/Q0Y Commented Dec 3, 2010 at 13:49

2 Answers 2

3

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>
Sign up to request clarification or add additional context in comments.

Comments

0

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);
            }
            });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.