Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    May 2007
    Location
    Manteca, CA
    Posts
    219
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Ajax - returning PHP file contents

    I recently had to reformat and reinstall everything from scratch. Now, the site I am building works fine on my provider's servers, but has a problem on my machine.

    I am using JQuery/Javascript & PHP. It appears that upon returning from the server side PHP code, the data returned (echo'ed) is the complete contents of the php file (not the json data i'm passing out). This is happening for all ajax calls. I'm thinking this must be something in the the php.ini file, but don't know what.

    A typical ajax caller and handler in my code looks like...

    Code:
    function jsFunction(){
    	obj.item1 = "item1_input";
    	obj.item2 = "item2_input";
    	var dataString = $.toJSON(obj);
    	alert("Before Update.....  "+dataString);
    	$.post(handler.php', {data: dataString}, done_function); 
    }
    
    function done_function(res){
    alert(res);
    }
    Using this simple php code...

    PHP Code:
    <?php
    //     
    $res json_decode($_REQUEST["data"], true);
    // ...
    // ... Processing and modifying contents of "data"
    // ...
    echo json_encode($res);
    return 
    1;
    ?>
    The value returned to the done_function (res) is the actual contents (code) of the php file, not the data that was echo'ed. Is this due to a setting in php.ini? This code worked fine before the crash and works fine on my provider's server.
    Last edited by snoodle; 03-20-2009 at 03:58 PM. Reason: clarity

  • #2
    Regular Coder
    Join Date
    Feb 2009
    Location
    Wheeling, IL
    Posts
    358
    Thanks
    5
    Thanked 62 Times in 60 Posts
    Sounds more like... there is no php server running. Are you opening the site locally with a "file:///xampplite/htdocs/whatever.php" or with a "http://localhost/whatever.php"? If the latter... is your apache (or whatever) running with php support?
    The way to success is to assume that there are no impossible things. After all, if you think something is impossible, you will not even try to do it.

    How to ask smart questions?

  • #3
    Regular Coder
    Join Date
    May 2007
    Location
    Manteca, CA
    Posts
    219
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Yeah, phpMyAdmin isn't working either. It did at one point since that was how I imported the database from my host's server. When I try to run phpMyAdmin I get, "Cannot load mysqli extension. Please check your PHP configuration. - Documentation".

    The Apache modules include php5_module. What else should I check? Should I just reinstall WAMP or... do you know how I get php back? (I'd rather learn something than just blindly try it again).

  • #4
    Regular Coder
    Join Date
    Feb 2009
    Location
    Wheeling, IL
    Posts
    358
    Thanks
    5
    Thanked 62 Times in 60 Posts
    Remotely? Doubtful. You could always ask in the PHP forums instead, might get a better reply... or rather in the software forum, considering the question isn't related to PHP coding, but to the installation and running of Apache with PHP support.
    The way to success is to assume that there are no impossible things. After all, if you think something is impossible, you will not even try to do it.

    How to ask smart questions?

  • #5
    Regular Coder
    Join Date
    May 2007
    Location
    Manteca, CA
    Posts
    219
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Strange. I reinstalled WAMP. phpMyAdmin comes up fine but my jquery ajax calls are still returning the contents of the php file being summoned. I'm losing it.

  • #6
    New to the CF scene
    Join Date
    Nov 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I had this problem too. The php script was being returned instead of the expected echoed value.

    I had upgraded from php4 to php5.

    The problem was caused by myself using a combination of long and short tags.

    In the php.ini file for php5 'short_open_tag' was set to 'off'

    The solution is either 'do not use short tags' of set 'short_open_tag' to 'on'

    Hope this helps

  • #7
    Regular Coder
    Join Date
    May 2007
    Location
    Manteca, CA
    Posts
    219
    Thanks
    4
    Thanked 0 Times in 0 Posts
    it's been so long i forgot how i solved the problem. i know i've run into the tag problem at least once before. anyway, thanks for the reply.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •