Jump to content

calling php file using ajax not working


googlexx

Recommended Posts

i'm trying to call a php file using ajax and it seems to be returning false, but i have no idea why. any ideas?

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>

<form method="get" action="test.php">
    <input id="myvar" type="hidden" name="albumid" />
    <button type="submit" id="btnsubmit">Submit</button>
</form>

<script type="text/javascript">
    $('form').submit(function() {  
        $.ajax({
            url: "newAlbum.php",
            data: {albumid: $('#myvar').val()},
            success: function(data){
                 var album = data;
                 $('#myvar').val(album);
                 return true;
             }
          });   
        return false;
    });
</script>

newAlbum.php

<?php echo '11'; ?>

test.php

<?php echo $_GET["albumid"]; ?>

 

 

 

Link to comment
Share on other sites

I think you need to indicate the type of data you are sending to the other page. e.g. post, get, json, etc..

This is the format that i use:

$.ajax({
   type:  'post'
,  url:   'path/to/file.php'
,  data:  {
      send:   'var'
   }
,  success: function( data ) {
      $('#target_element').html(data);
   }
});
Edited by robertjoep
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.