I am still learning Laravel 4 so I have a resourceful controller tasks and I am having a problem implementing my jquery.
My delete works fine without jquery so i think that I am not providing the proper url
I have found one problem I don't know how to pass my id to jquery,it apears that is not assigned.

$('#delete').on("click",function(event) {
    var answer = confirm('Are you sure you want to delete this?');
if (answer===true)
    url: 'tasks/'+id,
    type: 'POSt',
    success: function(result) {
        // Do something with the result

  return false;

My view with the delete part

{{ Form::open(array('method'=>'DELETE', 'route'=>array('tasks.destroy', $t->id))) }}
                {{Form::submit('Delete',array('class'=>'btn btn-danger','id'=>'delete'))}}

Thank you for your help

Recommended Answers

All 9 Replies

Member Avatar
 url: 'tasks/'+id,

From where are you getting the 'id'?

That is my problem I don't know how to get it because I am using it directly in the route.
So I can't do this .

This is what it should go to my

url:route'=>array('tasks.destroy', $t->id

But i don't know how to make it work

Member Avatar

You seem to be mixing up your php and js vars.

I know that I can't mix php with jquery.I want to find a way to get the action form the delete form to my jquery.
For an input I would do it like this.


I will dig deeper to see if I can find what i am looking for

Thanks for the reply.

Ok I found out that I can use the attribute method from jquery.

Now I have the delete working but i get 500 error form the server

var del = $('form').attr('action');
data={_method: 'delete' };

    url:  del,
    type: 'POSt',
    success: function(result) {
        console.log('You have deleted me.');

The error

DELETE http://ltask.dev/tasks/7 500 (Internal Server Error)    jquery-1.10.2.min.js:6
send jquery-1.10.2.min.js:6
x.extend.ajax jquery-1.10.2.min.js:6
(anonymous function) main.js:17
x.event.dispatch jquery-1.10.2.min.js:5
v.handle jquery-1.10.2.min.js:5

Ok it is working now I had a problem with my cache form the browser Thank you everyone.

Have you tried to change the type, in the ajax call, to DELETE?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.