简体   繁体   中英

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

$.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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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