Reputation: 11
The error console shows the following error:
Error: review is not defined Source File: http://localhost/opencart/index.php?route=information/savingsaccount Line: 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??
Upvotes: 0
Views: 429
Reputation: 50966
Try this
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);
}
there was some garbage so I removed it and it should work (like $.ajax()
just after function review(id) {
)
Upvotes: 3
Reputation: 3542
If you don't want your code to freeze while waiting on the response (which it will if you use async false), you should pass in a success handler which will be called once the response is received, something like:
function sendAjax() {
$.ajax({
// arguments
},getResponse);
}
function getResponse(response) {
// deal with what came back
}
Upvotes: 1
Reputation: 943142
The function definition of review
is hideously broken.
You start out by calling $.ajax
and passing it what looks like a object literal until you get to the first line inside it, at which point you appear to be trying to write a function.
I suggest making use of jslint
Upvotes: 2