PHP හෙල්ප් එකක්

hspa3.5

Well-known member
  • Sep 23, 2009
    4,539
    543
    113
    my world
    මේ තියෙන්නේ Ajax එක
    <script>
    $(function() {


    $.post(url, data, function(res) {

    console.log(res);

    console.log(res.stat);
    console.log(res.finalID);

    },' json ');


    });

    </script>


    මේකයි call karana කරන function එක

    public function TestJson() {
    echo 'inside test json function<br>';
    $res['stat'] = true;
    $res['finalID'] = 45;
    echo json_encode($res);
    }


    ඔය console.log කරල තියෙන දෙකම undefinned කියල එන්නේ ,ඒත් function එකෙන් හරියට echo වෙනවා {"stat":true,"finalID":45}

    rep denawa 4+ bump 1k වත් දාපල්ලා
     
    Last edited:
    • Like
    Reactions: ftthushara

    hspa3.5

    Well-known member
  • Sep 23, 2009
    4,539
    543
    113
    my world
    console.log(res); mekenmokadda print wenne?



    වැඩේ ගොඩ මචන් ඔය දාලා තියෙන echo 'inside test json function<br>'; හින්ඩ ජේසන් වලට පෙන්නනේ නැ.. thanks machan....
     

    mr90486

    Well-known member
  • Sep 2, 2008
    1,705
    1,476
    113
    Everywhere
    වැඩේ ගොඩ මචන් ඔය දාලා තියෙන echo 'inside test json function<br>'; හින්ඩ ජේසන් වලට පෙන්නනේ නැ.. thanks machan....

    yea, that maybe the reason. didn't think of it at first. good luck :)
     

    hspa3.5

    Well-known member
  • Sep 23, 2009
    4,539
    543
    113
    my world
    oya php function eka mokak hari class ekak atuleda thiyenne?

    try putting the following line on top of the first console.log statement.

    var json = JSON.parse(res);

    then try console.log(json) or console.log(json.stat) or console.log(finalID)

    this should work. for more info visit: http://www.mkyong.com/javascript/how-to-access-json-object-in-javascript/

    yea, that maybe the reason. didn't think of it at first. good luck :)

    thanks mcahan....