2016-03-30 35 views
1

Veritabanımdan, özellikle de iki sütundan veri elde eden bir Ajax İsteğim var, company_id ve people_id, Json sonucundan gelen sonucu test etmem gerekiyor, belirli bir people_id'in var olup olmadığını kontrol etmem gerekiyor sonuç, İşte Döndürülen json sonucu nasıl test edilir?

Ben başarı işlevinde bu aşağıdaki kodu yapabilirdi ama burada da

if (data == 0) { 
    Ext.MessageBox.alert('Status', 'Person is not attached to anything bud!.'); 
} 
else { 
    Ext.MessageBox.alert('Status', 'Person already attached to another company.'); 
} 

işe yoktu düşünce benim php benim Ajax İsteği

Ext.Ajax.request({ 
    url: 'system/index.php', 
    method: 'POST', 
    params: { 
     class: 'CompanyPeople', 
     method: 'secget', 
     data: Ext.encode({ 
      people_id: Ext.getCmp('peopleGrid').selectedRecord.data.people_id 
     }) 
    }, 
    success: function (response) { 

    }, 
    failure: function() { 

    } 
}); 

olduğu

class CompanyPeople extends Connect { 

    function __construct() { 
     parent::__construct(); 
    } 

    public function secget($vars) { 
     $sql = "SELECT * FROM CompanyPeople where people_id={$vars->data->people_id}"; 

     $data = array(); 

     $total = 0; 
     if ($result = $vars->db->query($sql)) { 
      while ($row = $result->fetch_assoc()) { 
       $data[] = array("people_id" => intval($row["people_id"])); 
       $total++; 
      } 
      $result->free(); 
     } 

     echo json_encode(array("success" => true, "total" => $total, "topics" => $data)); 
    } 
} 
+0

benim kod biçimlendirme sabitleme için deyimi ise –

+0

sayesinde koymak ne kadar emin değilim, ben korkunç –

cevap

1

Böyle bir şey çalışması gerekir düşünüyorum:

success: function(response){ 
    if(response.success === true) { 
     var personExist = false; 

     for(var i = 0; i < response.topics.lenght; ++i) { 
      // Your specific people_id in myValue 
      if(response.topics[i]['people_id'] === myValue) { 
       personExist = true; 
       break; 
      } 
     } 
    } 
}, 
+0

teşekkürler ben biliyorum şimdi deneyecek –

İlgili konular