1

My purpose is :

  1. Getting clicked button's id
  2. Post this id number to a controller's method.

Note that my routes are working nice. But when i try to pass data, i am having problems.

Here is jQuery :

$.ajax({
            type: "POST",
            url : "myRouteURL",
            data: (jQuery(this).attr("id"))
        });

Here is my controller's method :

public function somethingSpecial($passedData){
   DB::table('myTableName')->where('fieldName', '=', $passedData)->delete();
}

Thanks in advance.

1
  • Use only $ or Jquery don't use both in your code Commented Nov 24, 2014 at 12:36

2 Answers 2

2

I'm not sure what's $passedData value. Why don't you try sending your id with a name, that way you can get it later in your code. Here's an example:

jQuery:

$.ajax( {
    type : 'POST',
    url  : 'myRouteURL',
    data : { id : this.id }
} );

Controller's method:

public function somethingSpecial()
{
    $id = Input::get( 'id' );
    // you probably want to validate this value...
    DB::table( 'myTableName' )->where('fieldName', '=', $id )->delete();
}
Sign up to request clarification or add additional context in comments.

Comments

1

If you POST it to a certain route, then just add a post method in your routing. Then define that method in the controller. Hope this helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.