这是我的代码,其中包含使用ajax和jquery的表单。每当我刷新页面时,我都会在控制台选项卡的inspect元素区域中收到此错误:
SyntaxError:unterminated string literal
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Ajax Test</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<script>
$(document).ready(function() {
$('form[id=test_form]').submit(function (event) {
event.preventDefault();
var inp = $("#test_input").val();
var sub = $("#test_submit").val();
$(".test_msg").load("hello_ajax.php", {
inp: inp,
sub: sub
});
});
});
</script>
</head>
<body>
<h2>Testing Ajax</h2>
<form id="test_form" action="hello_ajax.php" method="POST">
<input type="text" id="test_input" name="tst_input">
<button type="submit" id="test_submit" name="tst_submit">Submit</button>
<p class="test_msg"></p>
</form>
</body>
</html>
答案 0 :(得分:0)
我认为这一行是问题
$('form[id=test_form]').submit(function (event) {
尝试使用:
$('#test_form').submit(function (event) {
和...
var sub = $("#test_submit").val();
提交按钮没有值
<button type="submit" id="test_submit" name="tst_submit">Submit</button>