0

My work host has an old version of PHP and it's not supporting json_encode(), so I need another way to pass array of strings from PHP to JavaScript, can't figure out how.... please help.

This is my current working code that's needed "downgrade":

PHP:

$arr = array($first_name,$last_name, $phone, $email, $number);
echo json_encode($arr);

JAVASCRIPT (ignore the missing brackets):

function get_repeat_request_details(request_id){
    if (window.XMLHttpRequest)
    {
        xmlhttp=new XMLHttpRequest();
    }
    else
    {
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200){
            var arr = JSON.parse(xmlhttp.responseText);
            document.getElementById("tb_f_name").value = arr[0];
            document.getElementById("tb_l_name").value = arr[1];
            document.getElementById("tb_phone").value = arr[2];
            document.getElementById("tb_email").value = arr[3];
            document.getElementById("tb_number").value = arr[4];
4

1 に答える 1

1

使用について:http ://www.dzone.com/snippets/jsonencode-alternative-php-4

すでに存在するかどうかを検出しますjson_encodeが、存在しない場合は、代替手段を提供します。

于 2012-07-23T14:39:26.307 に答える