下面是代碼,我是新的CS購物車,無法弄清楚如何從tpl在PHP文件中獲得ajax調用。 我想實現一個文件上傳功能到CS購物車的管理面板。 鉤/ order_management/upload_data.tpl '如何發送一個ajax請求到控制器後端php文件從CS購物車中的tpl文件?
$(document).ready(function(){
alert("doc ready");
$("#btn_ok").click(function(event) {
event.preventDefault();
var val = $("#myfile").val();
var data = "data=" + val;
$.ajax({
type: "POST",
url: '../../../app/addons/ugw_upload_form/controllers/backend/order_management.post.php',
data: data,
cache: false,
success: function(response)
{ console.log(response);}
});
});
});
</script>
<div class="control-group">
<input type="text" name="myfile" id="myfile" />
<input type="button" id="btn_ok" name="submit" value="upload" >
</div>`
控制器/後端/ order_management.post.php
'
if (!defined('BOOTSTRAP')) { die('Access denied'); }
use Tygh\Registry;
Registry::get('view')->assign('test_var', "Test");
Registry::get('view')->assign('uploadhere', "upload the file here");
if(isset($_POST['data'])){
$textvalue = $_POST['data'];
$handle = fopen("Z:\members.txt", "w");
fwrite($handle, $textvalue);
fclose($handle);
}
?>`