Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
577 views
in Technique[技术] by (71.8m points)

html - Pass Javascript value as part of php url parameter

I want to pass a JavaScript variable as comment parameter in disableReason function in redirectLocation as part of URL. I have got text area value from

var disableComment = document.getElementsByClassName("disable-comment")[0].value;

I am not able pass the javascript var into the url as parameter .

$html .= '<button type="button" class="scalable back" onclick="showDiv()">' . __($sellerText) . '</button>';
$html .= '<script>function showDiv() {document.getElementById("disable-reason").style.display = "block";}</script>';    
$html .= '<div style="display:none" id="disable-reason"><label for="disable-reason">Disable Reason</label><textarea class="disable-comment" name="disable-comment" rows="2" cols="25"></textarea><button type="button" class="scalable back" onclick="disableReason()">' . __($sellerText) . '</button><script>function disableReason() {var disableComment = document.getElementsByClassName("disable-comment")[0].value;redirectLocation('' . $this->getUrl('mpadmin/marketplace/sellerAccountEnable', ['id' => $data['entity_id'],'status'=>$sellerStatusData,'comment'=>'**variable here** ']) . '');}</script></div>';

Can you please help .


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

we can access Php variable using JavaScript. but we can't directly access JavaScript variable value using Php because php, python, java that are Server Side Languages. and JavaScript, jQuery is a Client Side Languages...

for Pass Value of Javascript Variable to Server Side languages you need to Call AJAX Request

$.ajax({
   url: example.com/test.php, //pass here Url...
        type: 'GET', //method type ... GET, POST
        dataType: 'html', //(html or JSON) not necessary but if you want to need pass then you can..
        headers: {
            // if you need pass authentication tokens then you can do it using headers in AJAX request
        },
        data: { 
            id: id; // pass here your data which you want to pass
        },
        success: function (data) {
            here you will be get success Response
        }
    });

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...