0

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) {
    event.preventDefault();
    var answer = confirm('Are you sure you want to delete this?');
if (answer===true)
{
    $.ajax({
    url: 'tasks/'+id,
    type: 'POSt',
    success: function(result) {
        // Do something with the result
    }
  });
}




else
{
  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'))}}
                {{Form::close()}}

Thank you for your help

Edited by dany12: more info

3
Contributors
9
Replies
27
Views
4 Years
Discussion Span
Last Post by cereal
0
 url: 'tasks/'+id,

From where are you getting the 'id'?

0

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 .

0

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

0

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

0

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.

$('input').val();

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

Thanks for the reply.

0

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

Edited by dany12

0

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

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

    $.ajax({
    url:  del,
    type: 'POSt',
    data:data,
    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
0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.