If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 3 of 3
  1. #1
    Senior Member shoffman3572's Avatar
    Join Date
    Jul 2008
    Fullerton, CA
    Member #
    Maybe someone here has a clue as to why this isn't working...

    Here's the javascript:

    function verify()
    $.post("/test/testCheck.php", {variable1: 1, variable2: 2}, function(data) { alert ("Made it here: data =" + data +""); } );

    Here's the php:

    $var1 = $_POST['variable1'];
    $var2 = $_POST['variable2'];
    echo $var1 . " - " . $var2;
    if($LogFile=fopen("/var/log/webserver/nameCheck2.log","a")) {

    when I check the log file produced - I see the two variables being passed to the php file. Whether I PRINT or ECHO var1 and var2 doesn't make any difference... I have also tried using $.ajax instead and I still get the same thing - the data is being sent to the php file, the php does work - it's just not returning the information to the javascript function.. any ideas?


  3. #2
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Not from USA
    Member #
    2783 times
    You have to output it as XML. Make sure you're returning the correct text/xml header too. About 95% of AJAX problems where the information isn't passed back are caused by this.

    jQuery in particular is really anal about looking for a properly formatted XML document, which is done on the PHP side of things.
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)

  4. #3
    Junior Member
    Join Date
    May 2011
    Austin, TX
    Member #
    2 times
    Here's a quick example of an AJAX-PHP submission via POST and additional callback from PHP to AJAX to return a successful submission:

    [COLOR=rgb(20, 20, 20)][COLOR=rgb(20, 20, 20)]1) Add to form page header:[/COLOR][/COLOR]
    <script src="" type="text/javascript"></script>
    <script type="text/javascript">
    function postPHP(){
    $.post("update.php", { 'FirstName': $('#FirstName').val(), 'LastName': $('#LastName').val() },
    //Successful POST returns Alert

    [COLOR=rgb(20, 20, 20)]2) Set up the form(doesn't require <form> tags for an AJAX call):[/COLOR]

    <input type='text' name="FirstName" id="LastName" /><br>
    <input type='text' name="LastName" id="LastName" /><br>
    <input type="submit" onclick="javascript:postPHP();" value="Post to PHP" />

    [COLOR=rgb(20, 20, 20)]3) Add a callback function to your PHP to indicate whether or not the POST was successful:[/COLOR]

    $FirstName = $_POST['FirstName'];
    $LastName = $_POST['LastName'];
    echo $FirstName;
    echo $LastName;
    //Callback to form page to indicate a successful POST
    function talkBack($callback){
    $data = "AJAX-PHP POST";
    function myCallback($data){
    print ' was successfully passed using ' . $data . "\n";

    [COLOR=rgb(20, 20, 20)]Hope this helps and let me know if you'd like a copy of the full source for a working example.[/COLOR]

    [COLOR=rgb(20, 20, 20)]Brandon[/COLOR]

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
All times are GMT -6. The time now is 06:54 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2020 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: