如何将php变量添加到Jquery UI对话框模式框中,例如,我有一个表单,其中包含了要插入数据库的信息,当用户单击submit按钮时,insert查询将执行,一旦成功,我将使Jquery UI模式框出现在页面上,并询问用户是否要插入新项,但如何用php值重定向页面?
这是modal box需要重定向的实际链接:Home/Purchase_Order_Pricing?code=EGX8T6GC2SI7
这是我的代码:
$code = $this-input->post('code');
<!doctype html>
<html lang='en'>
<head>
<meta charset='utf-8'>
<title>jQuery UI Dialog - Modal confirmation</title>
<link rel='stylesheet' href='//code.jquery.com/ui/1.11.0/themes/smoothness/jquery-ui.css'>
<script src='//code.jquery.com/jquery-1.10.2.js'></script>
<script src='//code.jquery.com/ui/1.11.0/jquery-ui.js'></script>
<script>
$(function() {
$( '#dialog-confirm' ).dialog({
height: 50,
width: 350,
modal: true,
resizable: true,
dialogClass: 'no-close success-dialog',
buttons: {
'Yes': function() {
window.location = 'home/purchase_order_pricing?code = $code';
},
No: function() {
$( this ).dialog( 'close' );
}
}
});
});
</script>
</head>
<body>
<div id='dialog-confirm' title='Add more items?'>
<p>asd</p>
</div>
<div id='popup-msg'>
<div id='loading'>
<h2>Loading...</h2>
<h3>Please wait a few seconds.</h3>
</div>
</div>
</body>
</html>
您可以将php变量传递给javascript,如下所示:
<script>
var code = "<?php echo $code; ?>";
</script>
并且可以在JavaScript中使用变量code
。这是您需要的吗?
例如:
window.location = 'home/purchase_order_pricing?code =' + code;