我想在AJAX函数中将数据许可证变量放到URL中。例如:
url: "localhost/test/index/license"
我似乎无法使其正常工作,并且传递给我成功的数据:function(data)
,不是我想要的字符串。下面是代码。请帮助我,谢谢你。
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#submit').click(function() {
var license = document.forms["license"]["license"].value;
var check = "^[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}$";
if(license.match(check)) {
alert("Successful");
}
else {
alert("Enter the licence in xxxx-xxxx-xxxx-xxxx format");
document.getElementById("license").focus();
}
$.ajax({
type: "get",
url: "localhost/test/index/",
data: license,
success: function(data) {
$('#message').html(data.trim());
}})
})
})
</script>
答案 0 :(得分:0)
在您的ajax功能中,添加您的许可证变量,如下所示。如果条件
,还要将你的ajax功能放在你的成功之中var license = document.forms["license"]["license"].value;
$.ajax({
type: "get",
url: "localhost/test/index/"+license,
data: license,
success: function(data) {
$('#message').html(data.trim());
}});
答案 1 :(得分:0)
请在ajax括号的末尾添加分号,您可以将许可证变量添加到url,如下所示:
cannot write to readonly table