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
https://forums.phpfreaks.com/topic/280383-calling-php-file-using-ajax-not-working/
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);
   }
});

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.