|
|
|
รบกวนหน่อยค่ะ อยากได้ค่า id ของ Script เอาออกมาใส่ช่องinput อีกช่อง ต้องทำยังไงค่ะ |
|
|
|
|
|
|
|
อยากได้ค่า ID มาแสดงที่ช่อง Mat เวลาSelection เลือกข้อมูลค่ะ
input.php
Code (PHP)
<tr>
<td height="33" style="font-size: 14px"> Description :<span style="text-align: left"> </span></td>
<td><select id='selUser' style='width: 300px;' >
<option value='0'>- Search -</option>
</select>
</td>
<td></td>
<td ></td>
</tr>
<tr>
<td height="33" style="font-size: 14px"> Material :<span style="text-align: left"> </span></td>
<td><input name="I_MATNR" type="text" id="I_MATNR" size="25"></td>
</tr>
<script>
$(document).ready(function(){
$("#selUser").select2({
ajax: {
url: 'getDatasap.php',
dataType: 'json',
type: "POST",
delay: 250,
data: function (params) {
return {
term: params.term
};
},
processResults: function (data) {
return {
results: data
//results: $.map(data, function(obj) {
//return { id: obj.id, text: obj.Section };
//})
};
}
}
});
});
</script>
getDatasap.php
Code (PHP)
include("Connect.php");
header('Content-Type: text/html; charset=utf-8');
$conn = new DB;
//print_r($_POST['term']);
//exit;
if(!isset($_POST['term'])){
//echo '1';
$fetchData = $conn->Selectrecordjoin("select TOP (5) PERCENT * FROM Mat_keyword order by id asc ");
}else{
//echo '2';
//print_r($_POST['term']);
$search = $conn->converttoutf8($_POST['term']);
$fetchData = $conn->Selectrecordjoin("select * FROM Mat_keyword where key_word Like '%$search%' ");
//$row = $conn->parseArray($fetchData);
//print_r($row);
//exit;
}
$data = array();
while ($row = $conn->parseArray($fetchData)) {
//print_r($row);
$Section = $conn->converttotis620($row['Description']);
$Material_Select = $conn->converttotis620($row['Material']);
//print_r($row);
$data[] = array("id"=>$row['id'],"Material"=>$row['Material'], "text"=>$Section);
}
echo json_encode($data);
Tag : PHP, Ms SQL Server 2008, HTML, JavaScript, Ajax, jQuery
|
|
|
|
|
|
Date :
2020-11-18 15:26:47 |
By :
mewhappy |
View :
749 |
Reply :
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (JavaScript)
processResults: function (data) {
console.log(data);// ได้ค่าอะไร?
// return ...
}
|
|
|
|
|
Date :
2020-11-18 15:46:45 |
By :
mr.v |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เขาน่าจะไม่รู้จัก console.log
|
|
|
|
|
Date :
2020-11-18 17:03:24 |
By :
guest |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|