การใช้ autocomplate ajax ในphpbb3

PHP Knowledge เป็น บอร์ดรวามความรู้ php เน้นบทความ แนวทางการเขียนโปรแกรม บันทึกกันลืม เพื่อให้สมาชิกได้เขียนความรู้ที่ตัวเองมีให้สมาชิกท่านอื่นๆ ได้ เข้ามาอ่าน และ ไว้อ่านเองกันลืมด้วย

Moderator: mindphp, ผู้ดูแลกระดาน

offing
PHP VIP Members
PHP VIP Members
โพสต์: 1527
ลงทะเบียนเมื่อ: 18/08/2014 10:01 am

การใช้ autocomplate ajax ในphpbb3

โพสต์ที่ยังไม่ได้อ่าน โดย offing »

ยกตัวอย่าง 1 เพจ

1.หน้าposting.php
-$template->set_filenames(array(
'body' => 'posting_body.html')
);
2.หน้า posting_body.html
-<!-- INCLUDE posting_layout.html -->
3.หน้าposting_layout.html
-<!-- INCLUDE overall_header.html -->
-<!-- INCLUDE posting_editor.html -->
-<!-- INCLUDE overall_footer.html -->
4.หน้าposting_editor.html
-<dl style="clear: left;">
<dt><label for="fmax_cps_name">{L_FMOD_SUBJECT_CUSTOMER}:</label>
</dt>
<dd>
<input autocomplete="off" type="text" id="fmax_cps_name" name="fmax_cps_name" class="fmax_cps_name inputbox autowidth" size="60" maxlength="<!-- IF S_NEW_MESSAGE -->80<!-- ELSE -->64<!-- ENDIF -->" tabindex="2" value="{NAME}{NAMEC}" <!-- IF CO_SUB !== 1 --> disabled <!-- ENDIF --> />
<span id="cps_id_error" class="error"></span>
<input type="hidden" name="fmax_cps_id" class="fmax_cps_id" value="{ID}">
<input type="hidden" name="fmax_cps_id_o" id="fmax_cps_id_o" value="{ID}">
</dd>
</dl>

เรียกคลาส fmax_cps_name

5.หน้าoverall_footer.html
jQuery('.fmax_cps_name').typeahead({
ajax : './ajax.php?mode=fmax_customer&',
onSelect : displayResult,
}).on('input',function(e){
fmax_cps_name = jQuery('#fmax_cps_name').val();
if(fmax_cps_name.length>1) {
cps_validate();
}
});
6.หน้าส่ง modeไปหน้า ajax.php
case 'fmax_customer':
$query = request_var('query', '');
$query = strtoupper($query);

$sql = "SELECT id, AES_DECRYPT( CompanyID, '". constant('M_KEY') ."' ) AS name1 " .
" , AES_DECRYPT( CompanyName, '". constant('M_KEY') ."' ) AS name2 " .
" FROM cps " .
" WHERE AES_DECRYPT( CompanyID, '". constant('M_KEY') ."' ) LIKE '".$db->sql_escape($query)."%'" .
" ORDER BY AES_DECRYPT( CompanyID, '". constant('M_KEY') ."' ) ASC " .
" LIMIT 0,8";
$re = $db->sql_query($sql);
//echo $sql;
$response = array();
while($fmax_row = $db->sql_fetchrow($re)){
$a_fmax_row = array('id'=>$fmax_row['id'], 'name'=> $fmax_row['name1'] .' >> ' . $fmax_row['name2']);
$response[] = $a_fmax_row;
}
echo json_encode($response);
break;

หน้านี้select ละก็ถอดรหัสตามอักขระมา8ตัว และเข้ารหัสเป็นjson และนี่เป็นข้อมูลในautocomplete
  • Similar Topics
    ตอบกลับ
    แสดง
    โพสต์ล่าสุด

ผู้ใช้งานขณะนี้

สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 80