0

I have this simpel ajax call to a php page.

$(document).ready(function(){

     $('#imgUpload').on('change', function () {
        $.ajax({
            url: './php/dataUpload.php',  
            type: 'POST',
            data: {boxId: boxId },
            dataType: "html",
            success: function(data){
                var box = $(data);
                alert('Do it!');
            },
        });
    });
});

On change the js-code will executed and I get a response from the php code. I don't know why however the result is the whole php code and not only the echo's..

The php code is:

<?php
    if(isset($_POST['boxId'])){
        echo $_POST['boxId'];
    } else {
        echo "blub";
    }
?> 

It's on a local server. Calling the php code only will echo "blub" to the browser-window so the php-code works.

Here the result of the ajax call if changed it to <?php echo "blub"; ?>:

"<?php↵ echo "blub";↵?>"
Andreas
  • 636
  • 1
  • 12
  • 29
  • Are you sure about when changes made it goes to `dataUpload.php`? Could you try with simple example like `echo 'hello world';`? – Ranjith Jun 19 '14 at 09:57
  • *"result is the whole php code and not only the echo's."* and *"Calling the php code only will echo "blub" to the browser-window so the php-code works."* is a contraction, isn't it? – Daniel W. Jun 19 '14 at 09:58
  • Try opening that php file URL with your browser.. you probably have miss configured PHP.. – Hardy Jun 19 '14 at 10:00
  • @DanFromGermany : I think he can't able to tell that clearly. – Ranjith Jun 19 '14 at 10:01
  • @DanFromGermany: calling a php-page over the browser is not the problem, it's only by calling with ajax... – Andreas Jun 19 '14 at 10:06
  • there is no relevant difference between an ajax request and a request made by the browser through the addressbar. It must be the same response. PHP is just not active/loaded/installed/configured on your localhost. – Daniel W. Jun 19 '14 at 10:08
  • Than tell me why I get no error on calling http://localhost/Homepage/php/dataUpload.php with the browser just the plain text blub.. – Andreas Jun 19 '14 at 10:13
  • @user2457241 right click and "view source" of the site, there is PHP code in. – Daniel W. Jun 19 '14 at 11:11
  • no there is only one line with the content "blub" nothing else – Andreas Jun 19 '14 at 11:58

0 Answers0