Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unwanted page refresh after AJAX request that runs SQL

On click of a button, I want to delete something from my database.

The following is my click handler.

$('.deleteLesson').click(function () {
    $.get('/Assignment/Modules/DeleteLesson.cshtml?LessonID=' + lessonID,function(data){
    });
});

Inside DeleteLesson.cshtml, I have the following

var db = Database.Open("database");
db.Query("DELETE FROM Lessons WHERE LessonID=@0", Request.QueryString["LessonID"]);

When the $.get runs, the SQL is performed on my database, but it forces a refresh on my original page. I can't figure out why. Through troubleshooting I have discovered it is purely the db.Query line that causes the refresh, and nothing else.

To be clear: I can comment out the db.Query line and it works exactly as I want it to (except it doesn't delete the item)

like image 968
Andy Avatar asked Mar 07 '14 00:03

Andy


1 Answers

I don't know whether to laugh or cry... it turns out my live.js was forcing the refreshes as it saw changes and wanted to update the page for me. (As intended, I just never expected it to do it in these circumstances).

Thanks for the help everyone...

like image 159
Andy Avatar answered Sep 22 '22 06:09

Andy