Click here to Skip to main content
15,890,186 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i know this is too easy and i do more but this time i don't have any solution for it
it always return empty string and if i print_r $x it print correct value

PHP
function call()
{
    $db_host     = 'localhost';
    $db_user     = 'root';
    $db_pass     = '';
    $db_database = 'peoplex'; 
    /* End config */
    $db = new PDO('mysql:host='.$db_host.';dbname='.$db_database, $db_user, $db_pass);
    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
    $result = $db->prepare("SELECT id,snap_url FROM live");
    $result->execute();
    $row= $result->fetch();
    // print_r($row['id']+2);
    return '<p>'+$row['id']+'</p>';
}

$x =''; 

if(isset($_GET['action']))
{ 
    //print_r("hhh");
    $GLOBALS["x"] = call();
    //print_r($GLOBALS["x"]);
    return $GLOBALS["x"];
}

<div id="live">t</div>

$( document ).ready(function() {
  console.log( "ready!" );
  start();
});

var i = 0;
function start()
{
    setInterval( function() {
        $.ajax({
            //  cache: false,
            type: "GET",
            url: "channel.php",
            datatype: "text",
            data: 'action=call',
            success: function (x, status, xhr)
                {
                    console.log(x);
                    document.getElementById('live').innerHTML =x;
                }
        }); // Ajax Call
    } //event handler
    ,33); //document.ready
}


What I have tried:

i use above code but did't run
Posted
Updated 5-Dec-16 22:55pm
v6

1 solution

i solved it now :D thanks every body it just add in if isset block after calling
echo
PHP
$GLOBALS["x"];

print_r it forced to print so it not correct if call from ajax or not
 
Share this answer
 
Comments
StM0n 6-Dec-16 4:56am    
Damn... to slow... I fiddled with your question.

BTW: This maybe an overkill, but I'm using the Slim Framework[^] for creating a php-ws.
Mahmoud_Gamal 6-Dec-16 5:04am    
thanks for improve question and your comment why you was fiddled by my question is it not clear and i will check slim framwork

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900