0

i wanted to bring this variable receiving_id inside the php link to process the link and insert the variable in the VAR_HERE

<script type="text/javascript">
    $(document).ready(function(){
        var receiving_id = $(this).attr('data-receivingId');

        $.ajax({
            url: "{{ route('acknowledge', ['receiving_id' => VAR_HERE, 'remark_id' => $data->remark_id, 'data_id' => $data->data_ids[0]]) }}",
            method: 'GET',
        });
    });
</script>
newbie
  • 81
  • 8
  • Can you show the route? – Sougata Bose Jun 14 '21 at 04:09
  • @SougataBose `Route::get('acknowledge/{receiving_id}/{remark_id}/{data_id}', 'DashboardController@acknowledge')->name('acknowledge');` – newbie Jun 14 '21 at 04:10
  • @Teemu I edited the question. I wanted it to open a new tab when submitting – newbie Jun 14 '21 at 04:13
  • @Teemu I dont have a problem with opening new tab. It's the var I have to insert inside the url im stuck with – newbie Jun 14 '21 at 04:16
  • At first, `this` inside `$(document).ready` refers to `document`, `document` doesn't have attributes. Secondly, it looks like you'd expect PHP to know a JS value before the JS is even executed. JS executes on your browser, PHP is run on your server for a long time before your browser parses the page. – Teemu Jun 14 '21 at 04:33

1 Answers1

0

Once the value is calculated, You will have to send the URL back with a variable in it within JavaScript. http://www.example.com/index.php?recieving_id=1

by using something like

window.location.href=”index.php?recieving_id=1"; Then in the PHP code use $_GET:

$somevar = $_GET["recieving_id"];

But this may cause an infinite loop. Therefore better check if that value is already passed or not before resending the request