[英]How do I $.post an array with jQuery so I can use the array in my PHP file?
[英]How do i use my jquery array in php code in 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);
}
});
沒有直接的方法,因為php首先在服務器端執行,而javascript在客戶端運行。
但是有一種使用這個數組的方法,
如代碼所示,該數組來自服務器響應,因此在從服務器發送數據之前,請將其保存在會話變量中,然后可以在服務器端使用會話變量
希望這個幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.