2011-04-12 4 views
0

PHP server side에는 클라이언트 측 정보를 업데이트하기 위해 JQuery으로 다시 전달하려는이 값이 있습니다.JSON을 통해 PHP에서 JQuery로 다중 값을 전달하는 방법은 무엇입니까?

예 :

fileSN fileTotalNumber fileTotalSize 
1  3    455 
2  4    555 
3  1    755 
4  1    155 

각 데이터 얻을 수있는 PHP 코드 :

$fileData = array(); 

while($row = mysqli_fetch_array($load_files_data_result, MYSQL_ASSOC)){ 

     $fileSN = $row['file_sn']; 
     $fileTotalNumber = $row['fileTotalNumber ']; 
     $fileTotalSize= $row['fileTotalNumber ']; 

     // only one data here , and need more data associated with fileSN 
     $fileData[$fileSN] = $fileTotalNumber; 

    } 

return json_encode($fileIds); 

그리고 클라이언트 측을 내 HTML 코드 :

<ul> 
    <li fileSN='1' fileTotalNumber='3' fileTotalSize='345'>update li information</li> 
    ... 
</ul> 

내 jQuery 코드 :

$.ajax({ 
    ... 
    success: function(result){     
    result = jQuery.parseJSON(result); 

    $.each(result, function(index, value) { 

     // need more values to update other attributes 

     $('#'+obj.FMMWID+'UL li[fileSN='+index+']') 
     .addClass('igtomdSelectedItem') 
     .attr('allfiles',value); 
     //console.log(value) 
    }); 
    } 
}); 

대단히 감사합니다!

+0

서버 쪽에서'echo json_encode ($ data)'해야하고 클라이언트 측에서는 JSON 사용 가능 데이터 형식의'$ .aja'x 호출을 수행하십시오. – kjy112

+0

예. 해냈습니다. 그리고 원하는 모든 데이터를 래핑하고 다시 JQuery로 전달하기 위해 데이터 구조가 필요합니다! – qinHaiXiang

답변

0

당신은 같은 테이블 정보의 연관 배열을 만드는 경우 :

$tableData[$rownumber]['field1'] = 'fieldvalue'; 
$tableData[$rownumber]['field2'] = '2ndFieldValue'; 

을 그리고 모든 행과 필드, 당신은 그 배열을 사용하여로 json_encode를 인코딩 할 수 그렇게(). 0가 유효한 행 번호와 필드 1은

data[0].field1 

배열 필드 중 하나입니다 : 당신이 data으로 jQuery를에 데이터를 반환하는 경우

그래서 당신은 다음과 같은 것들에 액세스 할 수 있습니다.

+0

작동합니다. 대단히 감사합니다 !! – qinHaiXiang

관련 문제