gpt4 book ai didi

javascript - 使用ajax响应获取文本框中的值

转载 作者:行者123 更新时间:2023-12-01 05:33:34 25 4
gpt4 key购买 nike

我希望在仅 Ajax 的帮助下获得经纪商选择管理员的佣金。

            <select id="user_id"  onchange="funCom(this);" >
<option value="" >Select Broker </option>
<?php $aData=$oGeneral->get_records('tbl_user');

$aUsertDetails = $oGeneral->aAdmin;
$iUserDetails = $oGeneral->iAdmin;
for($i=0;$i<$iUserDetails;$i++){?>
<option value="<?=$aUsertDetails[$i]['fld_id']?>">
<?php echo $aUsertDetails[$i]['fld_name']; ?></option>

<?php }?>
</select>
<input type="text" id="comm" name="fld_commision" value="" onkeyup="sum()" required>

函数调用

 function funCom(id){
id = id.value;

Token= "search-comm";
SendData= "Token="+Token+"&id="+id;


$.ajax({ url: 'Ajaxhandler.php',
dataType: 'text',
type: 'post',
async: false,
data: SendData,
success: function(data)
{


//var commision=stripHTML(data);
//$('#comm').val(commision); again not working
//$('#comm').text(data); Tried this but fail
$('#comm').val(data); //output is <body></body></html>7000
// i want only 7000 i have tried
},
error: function( jqXhr, textStatus, errorThrown ){
console.log( errorThrown );
} });


}

Ajaxhandler.php .
在这里我得到了需要放入文本框中的comsion值。该值显示在 <div> 中但我想要在文本框中。

<?php
require('../configuration/configuration.php');
$oGeneral = new GeneralClass();
$oUser = new UserClass();

$token= $_REQUEST['Token'];

switch($token) {
case 'search-comm': $id=$_REQUEST['id'];
$oUser->project_commision($id);
$aUsertDetails = $oUser->aResults;
$iUsertDetails = $oUser->iResults;
$total=0;
for($i=0;$i<$iUsertDetails;$i++){
$total+= $aUsertDetails[$i]['fld_commsionprice'];

}
echo $total;
break;
}

?>

最佳答案

将数据类型更改为 json 并尝试此操作。

函数调用

function funCom(id){
id = id.value;

Token= "search-comm";
SendData= "Token="+Token+"&id="+id;


$.ajax({ url: 'Ajaxhandler.php',
dataType: 'json',
type: 'post',
async: false,
data: SendData,
success: function(data)
{


//var commision=stripHTML(data);
//$('#comm').val(commision); again not working
//$('#comm').text(data); Tried this but fail
$('#comm').val(data.total); //output is <body></body></html>7000
// i want only 7000 i have tried
},
error: function( jqXhr, textStatus, errorThrown ){
console.log( errorThrown );
} });


}

是Ajaxhandler.php

$token= $_REQUEST['Token'];

switch($token)
{
case 'search-comm': $id=$_REQUEST['id'];
$oUser->project_commision($id);
$aUsertDetails = $oUser->aResults;
$iUsertDetails = $oUser->iResults;
$total=0;
for($i=0;$i<$iUsertDetails;$i++){
$total+= $aUsertDetails[$i]['fld_commsionprice'];

}
echo json_encode(array('total'=>$total));

break;
}

?>

关于javascript - 使用ajax响应获取文本框中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35391145/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com