2017-03-02 34 views
1
success: function (response) { 
    var paid = "PURCHASED"; 
    var notpaid = "PREMIUM"; 
    $.each(response['courceResults'], function(k, cource) { 
courceResultsData +='<tr><td>' 
    if(cource.membership_chosen == 3){ 
    if ($.inArray(cource.id , mystr) != -1) { /*alert(paid);*/ paid } 

在上面的行中有一個錯誤,當我警告它的價值 正確;但是當輸入變量或保持一個字符串「PURCHASED」if if 條件它不能正常工作我解決了這個連接..?顯示變量不工作在ajax響應

 else{ notpaid } 
    '</td></tr>'; 
    }); 
+0

可以爲用戶提供該問題的小提琴? – Mamun

回答

2

一些校正代碼: -

success: function (response) { 
    var paid = "PURCHASED"; 
    var notpaid = "PREMIUM"; 
    $.each(response.courceResults, function(k, cource) { //i think it's response.courceResults not response['courceResults'] check and change accordingly 
     var courceResultsData ='<tr><td>'; // missed ; 
     if(cource.membership_chosen == 3){ 
      if ($.inArray(cource.id , mystr) != -1){ // from where the hell mystr is coming? check yourself 
       courceResultsData +=paid; // forgot concatenation 
      } else{ 
       courceResultsData +=notpaid ; // forgot concatenation and missed ; 
      } 
      courceResultsData +='</td></tr>';//forgot concatenation 
     } // missed 
    } // missed 
    console.log(courceResultsData); //check the final output 
} // missed