简体   繁体   English

我如何在同一文件的php代码中使用我的jquery数组

[英]How do i use my jquery array in php code in same file

I am retrieving json from controller and want to use this json data in php file just Want to use jQuery GETGEN array in php in this same file 我正在从控制器中检索json并想在php文件中使用此json数据,只是想在同一文件中的php中使用jQuery GETGEN数组

$.ajax({
                url: '<?php echo site_url("movies/input/") ?>' + '/' + movie_id,
                type: 'post',
                data: "id=" + movie_id,
                dataType: 'json',
                beforeSend: function() {
                    $('.content').html('<div class="loader"><img src="<?php echo base_url("assets/images/loader.gif"); ?>"/></div>');
                },
                success: function(result) {
                    //console.log(result);
                    $("#id").val(result['movie_id']);
                    $("#title").val(result['title']);
                    var gen = result['genre'];
                    var getgen = gen.split(',');

                    $("#producer").val(result['producer']);
                    $("#director").val(result['director']);
                    $("#writer").val(result['writer']);
                    $("#music").val(result['music']);


                },
                error: function(jqXHR, status, error) {
                    if (status !== 'error')
                        alert(error);
                }
            });

there is no direct way because php execute at server side first and javascript run on client side. 没有直接的方法,因为php首先在服务器端执行,而javascript在客户端运行。

but there is a way to use this array, 但是有一种使用这个数组的方法,

as your code shows this array is coming from server response, so before sending data from server, save it in session variable and you can use your session variable at server side 如代码所示,该数组来自服务器响应,因此在从服务器发送数据之前,请将其保存在会话变量中,然后可以在服务器端使用会话变量

hope this help 希望这个帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM