错误控制台显示以下错误:
错误:未定义审核 源文件:http://localhost/opencart/index.php?route=information/savingsaccount 行:1
<script type="text/javascript">
function review(id) {
$.ajax({
alert(id);
text = $.trim($("#text").val());
name = $.trim($("#name").val());
rating = $.trim($("#rating").val());
url = "savingsreview.php";
data = "name="+name+"&text="+text+"&rating="+rating;
result = $.ajax({
url: url,
global: false,
type: "GET",
data: data,
async:false,
beforeSend: function(){
},
}
).responseText;
alert(result);
}
});
}
</script>
<div style="width:540px;" align="center"><a id="displayText"
href="javascript:toggle(<?php echo $id;?>);">Review & Read Reviews</a></div>
<span id="toggleText<?php echo $id;?>" style="display: none">
<div class="content">
<label><b>Your Name</b></label> : <input type="text" id="name" name="name" value="" />
<label><b>Your Review</b></label> :<textarea name="text" id="text" rows="3"> </textarea>
<label><b>Rating</b></label>
<input id="rating" type="radio" name="rating" value="1" style="margin: 0;" />
<input type="radio" name="rating" value="2" style="margin: 0;" />
<a onclick="review(<?php echo $id;?>);" class="button"><span>Submit</span></a></td>
</span>
Can anyone help me solve this??
答案 0 :(得分:3)
试试这个
function review(id) {
alert(id);
var text = $.trim($("#text").val());
var name = $.trim($("#name").val());
var rating = $.trim($("#rating").val());
var url = "savingsreview.php";
var data = "name=" + name + "&text=" + text + "&rating=" + rating;
var result = $.ajax({
url: url,
global: false,
type: "GET",
data: data,
async: false,
beforeSend: function() {},
}).responseText;
alert(result);
}
有一些垃圾,所以我删除了它,它应该可以工作(就像$.ajax()
之后的function review(id) {
一样)
答案 1 :(得分:2)
答案 2 :(得分:1)
如果您不希望代码在等待响应时冻结(如果您使用async false则会将其冻结),您应该传入一个成功处理程序,一旦收到响应就会调用该处理程序,如:< / p>
function sendAjax() {
$.ajax({
// arguments
},getResponse);
}
function getResponse(response) {
// deal with what came back
}