-3
我有一个创建一个简单的SMS验证器的要求,它检查*是否是开头符号,#是结尾。表单有一个文本输入字段和一个按钮验证。jquery没有从输入文本中读取特殊字符
单击按钮..它打印表单中的数据和第一个和最后一个字符。除了#和&以外,所有字符都可以正常工作。每当我输入这样的符号... jquery排除它。不知道这是什么解决方法。
<script type="text/javascript">
$(document).ready(function(){
$("#transactionForm").submit(function(event){
event.preventDefault();
var amountToSend = $("input#txnID").val();
//alert(amountToSend);
var length = $('input#txnID').val().length;
if(length > 3){
document.getElementById("loadingBlock").style.display = 'block';
document.getElementById("calculationBlock").style.display = 'none';
document.getElementById("errorBlock").style.display = 'none';
var url = '<?php echo API_URL ?>';
url = url+'/v1/smsValidator.php?txnID='+amountToSend;
//Start of AJAX call
$.ajax({
type: 'POST',
dataType: 'json',
url: url,
}).done(function(response) {
document.getElementById("loadingBlock").style.display = 'none';
var desc1 = $('#desc1');
var messageTitle = $('#messageTitle');
if(response.error){
document.getElementById("errorBlock").style.display = 'block';
$("#errorTitle").html(response.message);
}else{
document.getElementById("calculationBlock").style.display = 'block';
$("#messageTitle").html(response.message);
}
});
//End of AJAX call
}
});
});
</script>
请发布您的代码。 –
当然,因为你不是在'url'中转义这个特殊字符......'url = url +'/ v1/smsValidator.php?txnID ='+ encodeURIComponent(amountToSend);'。 –
如何以及因为您正在发送POST请求,为什么不在身体请求中设置此数据? '.ajax({data:amountToSend,...});' –