1

I'm trying to incorporate jquery ajax in my project, when i'm trying to delete a record i obtain a 500 (Internal Server Error).

my code

  <a href="javascript:checkDelete({{$model->id}});">Delete Model </a>

js

<script>


    function checkDelete(id) {
        if (confirm('Really want to delete?')) {
            $.ajax({
                type: "DELETE",
                url: '/admin/models/' + id,
                success: function(result) {
                    //
                }
            });
        }
    }
</script>

my routes:

Route::group(array('before' => 'auth'), function() {
    Route::resource('admin/users', 'UsersController');
    Route::resource('admin/posts', 'PostsController');
    Route::resource('admin/models', 'ModelsController');
    Route::resource('admin/models.pictures', 'PicturesController');
    Route::resource('admin/models.videos', 'VideosController');
    Route::get('dashboard', 'DashboardController@index');
    Route::get('admin/ayuda', function() {
        return View::make('admin.ayuda');
    });
});
4
  • 1
    The type of request to make ("POST" or "GET"), default is "GET". Other HTTP request methods, such as PUT and DELETE, can also be used here, but they are not supported by all browsers. Commented May 15, 2014 at 18:29
  • Can we see your route? Commented May 15, 2014 at 18:33
  • I edited to show my routes Commented May 15, 2014 at 18:43
  • Ok I changed the "DELETE" with "POST" and now i'm getting a 404... so i must be passing bad the url in my js function Commented May 15, 2014 at 18:46

1 Answer 1

-3
$.ajax({
    type: "GET",
    url: '/admin/models/' + id,
    success: function(result) {
         //
    }
});
Sign up to request clarification or add additional context in comments.

4 Comments

that's returns ok! when I alert on the success function, but doesn't delete the record from the database
Well you should take a look at your php code logic.
Never ever do any delete anything using GET. Ever. -1. GET is not supposed to change anything.
An answer ought to have a bit of explanation too, just plain code snippet is not a very good answer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.