javascript variable into php

前端 未结 3 576
生来不讨喜
生来不讨喜 2020-12-07 04:54

I have a php function, in this function I have a javascript which get the value of my element from parent window. My problem now is, how can I pass this value into php varia

相关标签:
3条回答
  • 2020-12-07 05:41

    The best you can do is make an ajax call to a server-side page which invokes the do_upload method for you:

    $.ajax({ 
        url: '/ajax.php', 
        data: 'category=' + window.top.window.$('#categories').val(), 
        type:'POST', 
        success:function(html){
        } 
    });
    

    ajax.php:

    if ( isset( $_POST['category'] ) ) {
        do_upload( $_POST['category'] );
    }
    

    Don't forget to filter the $_POST data to make sure its in the format you want.

    0 讨论(0)
  • 2020-12-07 05:43

    PHP code runs on the server (before your code is sent to the client browser), and JavaScript on the client (after the code is sent to the client browser). I'm not sure there is any other way to pass information to the server, other than sending a request to the server. so if you want to send something to your PHP application (server side) you'll have to send a request from your JavaScript code (client side). you may use AJAX techniques, but this causes another PHP process on the server to start. so you'll have to find a way to communication between the base PHP process (who created the JavaScript) and the new process (called by the JavaScript) to pass information. you may use server side data persistence like sessions or files or databases, or inter-process communication solutions like shared memory. but I guess this will get a little more complicated in implementation.

    0 讨论(0)
  • 2020-12-07 06:00

    The PHP print() language construct always returns 1.

    PHP executes on the server side. JavaScript executes on the client side. You cannot mix them directly. The best you could do would be to have JavaScript make an AJAX call to a PHP script on the server.

    0 讨论(0)
提交回复
热议问题