2013-12-16 58 views
0

這是Javascript代碼,我試圖獲得評論的列表視圖,當使用點擊電影時出現,但在控制檯中,我得到了第二個錯誤電影和第三,蝙蝠俠沒有定義,或頭像未定義,但與安娜卡列尼娜(有一個空間)說未捕獲的SyntaxError:意外的標識符 爲什麼會發生這種情況,我甚至編碼的PHP在PHP PHP代碼獲取值(x)未定義在AJAX中,web api

function reviews_get($title=null) { //GET : retrive all the reviews 
{ 
if (!isset($title)){// check if the ID is specified in the URI 
    $info->status = 'failure'; 
      $info->error->code = 11; 
      $info->error->text = 'title not specified in URI'; 
      $this->response($info, 400); 
}} 
{ // if the resource exist 
     $this->load->database(); 
     $sql = 'SELECT COUNT(Title) AS records FROM reviews WHERE Title = "'.$title.'";'; 
     //$this->response($sql, 200); 
     $query = $this->db->query($sql); 
     $data = $query->row(); 
     if ($data->records == "0") { 
      $info->status = 'failure'; 
      $info->error->code = 12; 
      $info->error->text = 'Title does not exist or have a resource'; 
      $this->response($info, 404); 
     } 
} 
    $this->load->database(); 
    $sql = 'SELECT id,Title,review,publisher,rating FROM reviews where Title="'.$title.'";'; 
    $query = $this->db->query($sql); 
    $data = $query->result(); 
$info->reviews = $data; 
$json = json_encode($info); 
    //$info->bytes = strlen($json); 

$this->response($info, 200); 
} 

的Javascript

//Get reviews for a partiluar movie    
      function Getreviewtitle(reviewtitle){ 
$.ajax({ 
    url:  "http://creative.coventry.ac.uk/~4078078/moviereviews/v1.0/index.php/review/reviews/"+reviewtitle, 
    dataType: 'json', 
    success: function(data) { 
    $("#allreviews").empty(); 
    reviewtitle=title; 
    console.log(reviewtitle);  
    $.each(data.reviews, function(i,review){ 
     $('#reviewlist').append('<li><a href="" data-transition="slide" onclick="Getreviewid('+review.id+')"> '+review.Title+' by '+review.publisher+': Rating: '+review.rating+'</a></li>'); 

    }); 
    $.mobile.changePage("#allreviews"); //show the results page 
    $('#moviereviews').listview('refresh'); 

    }, 
error: function (response) { 
    var r = jQuery.parseJSON(response.responseText); 
    alert("Message: " + r.error.text); 
       } 
    }); 
     } 

鏈接,如果你要測試的網站是:http://creative.coventry.ac.uk/~4078078/client3/ 如果您點擊評論在底部,然後點擊該頁面我想要顯示的電影,這些AR代碼爲它

回答

0

你忘了在你的字符串周圍加上引號。 例如,您具備以下條件:

<a href="#allreviews" data-transition="slide" onclick="Getreviewtitle(Batman)" class="ui-link-inherit">Batman <img src="icon.jpg" onerror="imgError(this);" class="ui-li-thumb" height="150" width="150"></a> 

更改爲:

<a href="#allreviews" data-transition="slide" onclick="Getreviewtitle('Batman');" class="ui-link-inherit">Batman <img src="icon.jpg" onerror="imgError(this);" class="ui-li-thumb" height="150" width="150"></a> 

您目前擁有的方式,JavaScript是尋找一個叫蝙蝠俠變量。

EDIT所以看來你是動態建立的聯繫,並與您的報價糊塗了,你有:

onclick="Getreviewtitle('+review.title+')">' 

您需要:

onclick="Getreviewtitle(\''+review.title+'\')">' 

注意額外的(逃跑),單引號標記

+0

BuT引號存在'onclick =「Getreviewtitle('+ review.title +')」>' – user3051827

+0

@ user3051827編輯說明 – Steve

+0

雖然顯示了輕微的變化,但是仍然是錯誤,頁面變成空白,並且還與安娜卡列尼娜它是說,這個標題不存在,是我在PHP 64 base編碼不正確? – user3051827

相關問題