[英]Ajax issue with “oninput” event
i'm trying to fire an oninput event on a number input field, the ajax call is always successful and showing the parameter sent in firebug's network-> params, however, when i want to retrieve the parameter sent via ajax, the isset() is not working and never getting a reply, for more clarification i will post parts of my code below : 我试图在数字输入字段上触发oninput事件,ajax调用始终成功,并显示在萤火虫的network-> params中发送的参数,但是,当我想检索通过ajax发送的参数时,isset()无法正常工作,永远也不会得到答复,为进一步澄清,我将在下面发布部分代码:
<label> Amount to Pay </label>
<div id="toBePaid" class="form-input-wide">
<input type="number" id="amountToBePaid" name="amountToBePaid" oninput="getRemainingAmount()" data-type="input-number" min="0" required style="width:100px;" size="5" value="<?php ?>" data-component="number" />
</div>
this previous the number that will be sent via ajax, the function is : getRemainingAmount()
这个先前的数字将通过ajax发送,该函数是: getRemainingAmount()
<label> Remaining Amount </label>
<div id="remaining" >
</div>
this div will contain the reply, it will be referenced in the script 这个div将包含回复,它将在脚本中引用
function getRemainingAmount() {
var amountToPay = $('#amountToBePaid').val();
var dataString = "amountToPay="+amountToPay;
$.ajax({
type: "POST",
url:'http://192.168.0.10/skylite/test',
data: dataString,
success: function(response) {
$("#remaining").empty();
$(response).find('.resultRemaining').each(function(){
$('#remaining').append($(this).html()); });
},
});
}
Now i will post "test" page, please note that the .empty()
is not the issue, the test page's code contain : 现在我将发布“测试”页面,请注意.empty()
不是问题,测试页面的代码包含:
if(isset($_POST['amountToPay'])) {
var $AmountToPay=$_POST['amountToPay'];
echo "<div class='resultRemaining'>";
echo "<input type='number' id='remainingAmount' name='remainingAmount' data-type='input-number' disabled style='width:100px;' size='5' value=".$AmountToPay." data-component='number' />";
echo "</div>";
} else {
// redirecting to my main page here
}
i'm appending resultRemaining
class to the function, if i remove my if(isset($_POST['amountToPay'])) {
the reply works if i input a dummy value. 我正在追加resultRemaining
类的功能,如果我删除我的if(isset($_POST['amountToPay'])) {
回复工作,如果我输入一个虚拟值。
Here's a small snapshot of the ajax call in "Network": 这是“网络”中ajax调用的小快照:
Your PHP code is invalid and will throw a parse error, since you have var
in front of your variable. 您的PHP代码无效,并且会引发解析错误,因为变量前面有var
。 The keyword var
was used in PHP 4 to declare class members. 关键字var
在PHP 4中用于声明类成员。 It can still be used (but seldom is) for declaring public class members, but it's not a valid keyword in any other context. 它仍然可以使用(但很少是)用于声明公共类的成员,但它没有在任何其他情况下有效的关键字。
It should work if you change the line: 如果您更改行,它应该可以工作:
var $AmountToPay=$_POST['amountToPay'];
to 至
$AmountToPay=$_POST['amountToPay'];
Demo about var
: http://3v4l.org/InhN7 有关var
演示var
http: //3v4l.org/InhN7
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.