i have an unexpected token : but i dont know why this is.
the code where it is happening.
<script type="text/javascript">
$('.delete-btn').click(function() {
$.ajax(function() {
type: 'POST',
url: 'ajax.php',
data: { filename: filename },
success: function(return) {
if(return == 'SUCCESS') {
$this = $(this).closest('tr');
$this.remove();
}
}
});
});
</script>
I hope someone can find why i get the unexpeded token : at the url: 'ajax.php', rule.
The syntax error is in your success
callback. You've named the argument return
, which is a reserved word. Call it something else.
Niet here, merging my answer into this one to complete the picture:
Change:
$.ajax(function() {
To:
$.ajax({
Pay closer attention to what you're writing :p
return
is a reserved word in JavaScript. Use any other name other than return. I have used data instead of return. Also there is type is an error in ajax function you have written. updated the same. Use the below code
<script type="text/javascript">
$('.delete-btn').click(function() {
$.ajax({
type: 'POST',
url: 'ajax.php',
data: { filename: filename },
success: function(data) {
if(data == 'SUCCESS') {
$this = $(this).closest('tr');
$this.remove();
}
}
});
});
</script>
return
is a keyword at javascript dont use it as a variable name
<script type="text/javascript">
$('.delete-btn').click(function() {
$.ajax(function() {
type: 'POST',
url: 'ajax.php',
data: { filename: filename },
success: function(data) {
if(data== 'SUCCESS') {
$this = $(this).closest('tr');
$this.remove();
}
}
});
});
</script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.