Question

i saw many solutions which are working for me too, but in this particular situation nothing works, i'll share the code and hope one can help me,

<head><script src="jquery-1.9.1.min.js"type="text/javascript"></script>
<script>
$(document).ready(function(){
var gg = 1;
$.post('11.php', {gg:gg});});</script>
<?php
include '11.php';
echo "</br>this is data</br>". $data;?>
</body>

and 11.php:

<?php  $data = $_POST['gg'];
echo "this is data from 11.php" .$data; ?>

i've tried before to solve this kind of problem and it worked well on localhost, but now on real hosting something goes wrong, i know it's duplicating, but can't find my mistake here, thank you in advance

Additionally: stackoverflow engine says: "This question may already have an answer here: Reference: Why does the PHP code in my Javascript not work? 2 answers" i can't see any relation with my question, but down votes are rising

Was it helpful?

Solution

You need to create a callback function on success you can't just include 11.php because that would not be in the ajax request therefore gg will not be passed.

$.post('11.php', {gg:gg},function(data){
    $('body').append(data);
    });
});

OTHER TIPS

You said that it is in hosting server then you need to change

$.post('11.php', {gg:gg} , function(data){
       alert(data);   //console.log
});

11.php file full path at the host should be given for the post..

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top