L
L
LP-DIMAN2015-12-02 11:04:49
PHP
LP-DIMAN, 2015-12-02 11:04:49

How to pass an arbitrary get parameter to an Ajax request?

$(document).ready(function(){
  // При нажатии на кнопку id=send
  $('#remember').click(function(){
    
  $.get('true_advert',{remember:""});


  });
});

From here you need to get the value
$id_advert = $_GET['remember'];
Here is the function:
protected function remember_adverts(Request $request)
  {
    if ($request->input('remember'))
    {
      $id_advert = $_GET['remember'];
      
      $client = Auth::user()->id;
      Adverts::remember_adverts($client,$id_advert);
    }
  }

Here is the view:
<button type="submit" value="{{$advert->id_realty}}" name="remember" id="remember">Запомнить</button>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Robot, 2015-12-02
@iam_not_a_robot

oid - an arbitrary parameter, you can pass it to both php and JS

$.ajax({
        url: 'yourphp.php',
        type: 'POST',
        dataType: 'html',
        data: { /* Данные для отправки */
            Oid: oid,
            /* На сервер придет:
            	$_POST = array(
            		Oid => oid
                );
            */
        },
    })

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question