0

I create the data and return it OK but for five hours I have been trying to decode it. I have tried every example I could find but each time come up with a different error. I have tried datatype "json" and "text json" also adding json to the call (I read somewhere that auto decoded it) The data being returned is fine but I need to extract it into separate variables. I found some jscript code to generate the array on the server but that failed too.

function getadvertxml(idprodxxx, offset, idwho) {
    $.ajax({
        url: 'xml_getadverts.php',
        dataType: 'json',
        data: {
            "idprodxxx": idprodxxx,
            "offset": offset,
            "idwho": idwho,
        },
        type: 'GET',
        success: function (data) {
            //          data = JSON_decode(data,true);
            data = JSON.parse(data);
            console.data;
            //                  $('#content_sidebar').html(data[5]);
        }
    });
}

Server:

  <CREATE DATA works OK checked on the console log>.......
  $arr[0]=$playerxy;
  $arr[1]="video16";//linkid
  if ($video1) {
    $arr[2]=$video1->urlvideo;//playerurl
    $arr[3]=$video1->urlwho;//linkurl
    $arr[4]=$video1->whodesc;//linkdes
  } else {
    $arr[2]="../../videos/default." . $ext;
    $arr[3]="http://notfound.com.au/";
    $arr[4]="Not found";
  }  
  $arr[5]=$HTML5;
  $arr=json_encode($arr);
  echo ("$arr");

This particular version's error is "SyntaxError: JSON.parse: unexpected non-whitespace character after JSON data" but I think I must have generated almost every JSON error there is with my attempts to get this working. Please help as I am starting to tear out my white hair.

Edit

    <?php
    error_reporting(E_ALL);
    ini_set('display_errors', '1');
    require_once("../../includes/initialize.php");
    require_once("../../includes/functions.php");
    require_once("../../includes/session.php");
    require_once("../../includes/database.php");
    require_once("../../includes/pageination.php");
    if ($session->is_logged_in()) {
        include '../../includes/load3who.php';
        $idworldview=$_GET['idworldview'];
        $idprodxxx=$_GET['idprodxxx'];
        $cat=$_GET['cat'];
        $perpage=$_GET['perpage'];
        $offset=$_GET['offset'];
        $page=$_GET['page'];
        $levela=$_GET['levela'];
        $idwho=$_GET['idwho'];
        $playerxy=1;
        $ext='ogv';
        $idworld=41;
        $reports = NULL;
        $find="|?|";
        $groupdesc= substr($cat,0,strrpos($cat, $find));                
        $catdesc= " " . substr($cat,strrpos($cat, $find) + 3);
        $HTML5="<center><small><h3>{$groupdesc}</h3></small></center>"; 
        $virgin = true; 
        $synopis = "";
            $pageination = new Pageination($page, $perpage);
            $reports = Report_as::find_reports($idworldview,$idprodxxx,$perpage,$offset);
            $ctreports=count($reports);
            $pageination->seteof($ctreports<=$perpage);
            if(!$pageination->iseof()){
                unset($reports[$perpage]); //remove extra row - retrieved to see if EOF
            }   
        foreach($reports as $rp) {
            if ($virgin) {
                $HTML5.='<table class="reporttable" border="1" width=100%>';
                $HTML5.= '<tr>';
                    $HTML5.= "<th align=center>{$catdesc}</th>";
                    $HTML5.= '<th align=center>Visit Website</th>';
                $HTML5.= '</tr>';
                $virgin = false;
            } else {
                $HTML5.= "</td>"; 
                $HTML5.= "</tr>";
            }
            $HTML5.= "<tr height=60px; max-height=60px; vertical-align=top>";
            $HTML5.= "<td align=top width= 70%>";
            $cust_rp = Report_as::find_cust_reports($rp->idprodcgs, $rp->idwho_cust);
            if (!$cust_rp) {
                $cust_rp = Report_as::find_cust_fallback($rp->idwho_cust);
            }
            $custurl = '<a href="' . $rp->urlcust . '"target="_blank">' . $rp->custdesc . '</a>';
            $HTML5.= '<a href="javascript:changesrc(\''.
                                        str_replace("'", "\\'",$rp->urlvideo).'\', \''.
                                        str_replace("'", "\\'",$cust_rp[0]->urlcustvideo).'\', \''.
                                        str_replace("'", "\\'",$cust_rp[0]->custdesc).'\', \''.
                                        str_replace("'", "\\'",$cust_rp[0]->urlcust) . '\')">' . $rp->synopsis . '</a>';
            $HTML5.= "</td>";
            $HTML5.= "<td>";
            $HTML5.= '<a href="' . $rp->urlwho . ' "target="_blank">' . $rp->mydesc .'</a>';
            if($levela == 'x') {
                $idprodxxx = $rp->idprodcgs;
            }
            $whoproducturl = Report_as::find_whoproducturl($rp->idwho, $idprodxxx);
            if ($whoproducturl) {
                foreach($whoproducturl as $wp) {
                    $HTML5.= '<br><a href="' . $wp->urlprod . ' "target="_blank">' . $wp->urldesc .'</a>';
                }
            }
        }
        $HTML5.="</td></tr></table><small><strong><center>";
        $HTML5.='<a href="javascript:emailme(\''.
                                        str_replace("'", "\\'", $user_id).'\', \''.
                                        str_replace("'", "\\'", $idprodxxx) . '\')">' . 'Email me' . '</a> when new reports are added to this category</center></strong></small>'; 

        $HTML5.="<input type='button' name='back' style='float:left' value=' &laquo; Menu 'onclick='location.href=\"index.php\"'/>";
        if($reports){
            $nextdisable=" disabled ";
            $prevdisable=" disabled ";
            $next1=" No more ";
            $prev1=" No more ";
                $holdoffset=$offset;
                $holdpage=$page;
                $updown='N';
                $nextdisable=" ";
                $next1=" &dArr; Next &dArr; ";
                $offset=$holdoffset+$perpage;
                $page=$holdpage+1;
                if($pageination->iseof()) {
                    $nextdisable=" disabled ";
                    $next1=" Finished ";
                }  
                $HTML5.="<input{$nextdisable}id=\"nbutton\" type=\"button\" name=\"next\" style= \"float:right\" value=\"{$next1}\" onclick=\"getreports('".
                                    str_replace("'", "\\'",$idworldview).'\', \''.
                                    str_replace("'", "\\'",$idprodxxx).'\', \''.
                                    str_replace("'", "\\'",$cat).'\', \''.
                                    str_replace("'", "\\'",$levela).'\', \''.
                                    str_replace("'", "\\'",$perpage).'\', \''.
                                    str_replace("'", "\\'",$offset).'\', \''.
                                    str_replace("'", "\\'",$page).'\', \''.
                                    str_replace("'", "\\'",$idwho).'\', \''.
                                    str_replace("'", "\\'",$playerxy).'\', \''.
                                    str_replace("'", "\\'",$ext).'\', \''.
                                    str_replace("'", "\\'",$idworld).'\'' . ")\"/>";

                if($pageination->haspreviouspage()) {
                    $updown='P';
                    $prevdisable=" ";
                    $prev1=" &uArr; Back &uArr; ";
                    $offset=$holdoffset-$perpage;
                    $page= $holdpage-1;
                    $HTML5.="<input{$prevdisable}type=\"button\" name=\"next\" style= \"float:right\" value=\"{$prev1}\" onclick=\"getreports('".
                                        str_replace("'", "\\'",$idworldview).'\', \''.
                                        str_replace("'", "\\'",$idprodxxx).'\', \''.
                                        str_replace("'", "\\'",$cat).'\', \''.
                                        str_replace("'", "\\'",$levela).'\', \''.
                                        str_replace("'", "\\'",$perpage).'\', \''.
                                        str_replace("'", "\\'",$offset).'\', \''.
                                        str_replace("'", "\\'",$page).'\', \''.
                                        str_replace("'", "\\'",$idwho).'\', \''.
                                        str_replace("'", "\\'",$playerxy).'\', \''.
                                        str_replace("'", "\\'",$ext).'\', \''.
                                        str_replace("'", "\\'",$idworld).'\'' . ")\"/>";
                }
        }
        $ix = -1;
        $kazvideo1 = p4::find_kazand(1,'ogv',41); // 1=top video
                $arr[0]=$playerxy;
                $arr[1]="video16";//linkid
                if (!$kazvideo1) {
                    $ixpos = rand(0,count($kazvideo1)-1);
                    $arr[2]=$kazvideo1[$ixpos]->urlvideo;//playerurl
                    $arr[3]=$kazvideo1[$ixpos]->urlwho;//linkurl
                    $arr[4]=$kazvideo1[$ixpos]->whodesc;//linkdes
                } else {
                    $arr[2]="../../videos/default." . $ext;
                    $arr[3]="http://notfound.com.au/";
                    $arr[4]="Not found";
                }  
                $arr[5]=$HTML5;
                $arr=json_encode($arr);
                die ("$arr");
    }
    ?>
4

1 回答 1

0

Server side:

$arr[0]=$playerxy;
$arr[1]="video16";//linkid
if ($video1) {
    $arr[2]=$video1->urlvideo;//playerurl
    $arr[3]=$video1->urlwho;//linkurl
    $arr[4]=$video1->whodesc;//linkdes
} else {
    $arr[2]="../../videos/default." . $ext;
    $arr[3]="http://notfound.com.au/";
    $arr[4]="Not found";
}  
$arr[5]=$HTML5;
die(json_encode($arr));

Client Side:

function getadvertxml(idprodxxx,offset,idwho){
    $.ajax({
        url : 'xml_getadverts.php',
        dataType: 'json',
        data:{ "idprodxxx":idprodxxx,
            "offset":offset,
            "idwho":idwho },
        type: 'GET',
        success: function(data){
            console.log(JSON.stringify(data))
        }
    });
}
于 2013-08-29T04:38:06.460 回答