我想在JavaScript代碼中傳遞一個帶有URL的變量。變量來自數據庫。我在StackOverflow中看到很多答案。但我認爲,對於我的問題,我找不到任何正確的答案。代碼如下:如何在JavaScript代碼中將URL傳遞給變量?
此代碼位於我的索引頁面。
<script type="text/javascript">
$(document).ready(function(){
$("#btn-view").hide();
$("#btn-add").click(function(){
$(".content-loader").fadeOut('slow', function()
{
$(".content-loader").fadeIn('slow');
**$(".content-loader").load('video_add.php?lang=$lang')**;
$("#btn-add").hide();
$("#btn-view").show();
});
});
$("#btn-view").click(function(){
$("body").fadeOut('slow', function()
{
**$("body").load('video.php?lang=$lang');**
$("body").fadeIn('slow');
**window.location.href="video.php?lang=$lang";**
});
});
});
</script>
此代碼是code.js文件。
// JavaScript Document
$(document).ready(function(){
/* Data Insert Starts Here */
$(document).on('submit', '#emp-SaveForm', function() {
$.post("video_create.php?lang=$lang", $(this).serialize())
.done(function(data){
$("#dis").fadeOut();
$("#dis").fadeIn('slow', function(){
$("#dis").html('<div class="alert alert-info">'+data+'</div>');
$("#emp-SaveForm")[0].reset();
});
});
return false;
});
/* Data Insert Ends Here */
/* Data Delete Starts Here */
$(".delete-link").click(function()
{
var id = $(this).attr("id");
var del_id = id;
var parent = $(this).parent("td").parent("tr");
if(confirm('Sure to Delete ID no = ' +del_id))
{
$.post('video_delete.php?lang=$lang', {'del_id':del_id}, function(data)
{
parent.fadeOut('slow');
});
}
return false;
});
/* Data Delete Ends Here */
/* Get Edit ID */
$(".edit-link").click(function()
{
var id = $(this).attr("id");
var edit_id = id;
if(confirm('Sure to Edit ID no = ' +edit_id))
{
$(".content-loader").fadeOut('slow', function()
{
$(".content-loader").fadeIn('slow');
$(".content-loader").load('video_edit.php?edit_id='+edit_id);
$("#btn-add").hide();
$("#btn-view").show();
});
}
return false;
});
/* Get Edit ID */
/* Update Record */
$(document).on('submit', '#emp-UpdateForm', function() {
$.post("video_update.php?lang=$lang", $(this).serialize())
.done(function(data){
$("#dis").fadeOut();
$("#dis").fadeIn('slow', function(){
$("#dis").html('<div class="alert alert-info">'+data+'</div>');
$("#emp-UpdateForm")[0].reset();
$("body").fadeOut('slow', function()
{
$("body").fadeOut('slow');
window.location.href="video.php?lang=$lang";
});
});
});
return false;
});
/* Update Record */
});
所有URL傳遞變量
LANG = $ LANG
。 $ lang是en或bn,但它來自數據庫表。我如何使它可用?
在javascript代碼中使用php什麼是 – Kumar
在js中回顯php需要使用<?php echo $ lang; ?> – Blinkydamo