Home>

In the jQuery written in the php file, PHP is written as follows.
I want to use jQuery variables in that PHP, what should I do?
Please professor.

When I try the code below, I get an error like this:
Undefined variable: value

Below in jQuery
{{Common :: getData (Config :: get ('const.PrefecturesList'), $value)}}
I'm writing php, and I want to use the value defined in js for the $value part.
It doesn't work. ..

$("select [name * ='japan_region']"). change (function () {
    var id = $(this) .attr ('id');
    var value = $(this) .val ();
    $("select [name ='japan. {$id} .japan_prefectures']"). val ('(['' =>'Please select a prefecture']] + {{Common :: getData (Config: : get ('const.PrefecturesList'), $value)}})');
  • Answer # 1

    I'm probably writing Laravel, so I'm assuming you're using a Blade template
    &{{Common :: getData (Config :: get ('const.PrefecturesList'), $value)}}Is assumed to be the part described in Blade


    PHP (blade) template processes PHP on the server and returns the result (HTML data) to the client

    JavaScript is described in HTML dataJavaScriptIt is processed based on the source of.

    Since it is independent, JavaScript variables cannot be used in PHP.
    To use it like thatajaxUsing etc.JavaScriptPass the variable of to PHP and get the resultJavaScriptIt will be processed with.