![](/img/trans.png)
[英]SQL query not being executed from AJAX '$_POST' to PHP file
[英]SugarCRM: PHP not being executed from ajax on custom button
我在自定義按鈕上執行ajax調用時遇到了一些麻煩。 自定義按鈕位於案例列表視圖上,列表中每個案例都有一個。 單擊后,此按鈕應執行對自定義終結點的ajax調用,將assigned_user_id更新為當前登錄的用戶,然后重定向到該按鈕與之關聯的情況。
當前,我正在訪問端點,並且可以記錄通過ajax調用發送的案例的ID,但是無法獲取該調用來更新分配給案例的用戶。
這是ajax調用:
function take_ticket(url, id) {
$.ajax({
url: '/custom/modules/Cases/assign_ticket.php',
contentType: 'JSON',
data: {
'id': id
},
success: function(response){
window.location = url;
//alert(response);
},
error: function(response) {
alert('Error');
}
});
return false;
}
這是我創建的自定義端點(請注意,我正在對用戶ID進行硬編碼以進行測試):
<?php
if ($_GET['id']) {
$test = $_GET['id'];
updateUser($test);
}
function updateUser($test) {
$case = new aCase();
$case->retrieve($test);
$case->assigned_user_id = 'a5c636c4-9712-d84a-7e81-585becf9dc52'
$case->save();
}
?>
如果刪除所有案例創建/更新邏輯並僅回顯$ test,我將獲得期望的響應。 但是,有了更新邏輯,即使我只是簡單地回顯$ test,我的響應也仍然是空的,並且案例沒有得到更新。
編輯:由於收到無效的入口點錯誤,我嘗試在include / MVC / Controller / entry_point_registry.php中為modules / Cases / case.php添加入口點:
$entry_point_registry = array(
'cases' => array('file' => 'modules/Cases/Case.php', 'auth' => false),
'takeTicket' => array('file' => 'custom/modules/Cases/assign_ticket.php', 'auth' => false),
'emailImage' => array('file' => 'modules/EmailMan/EmailImage.php', 'auth' => false),
.....
這沒有用,所以我在custom / Extension / application / Ext / EntryPointRegistry / customEntryPoint.php中添加了一個條目:
$entry_point_registry['takeTicket'] = array(
'file' => 'custom/modules/Cases/assign_ticket.php',
'auth' => false
);
$entry_point_registry['cases'] = array(
'file' => 'modules/Cases/Case.php',
'auth' => false
);
根據提供的信息,對文件進行了一些更改:
自定義/模塊/案例/assign_ticket.php
$case->assigned_user_id = 'a5c636c4-9712-d84a-7e81-585becf9dc52'; //Added semicolon (syntax error)
自定義/擴展名/應用程序/Ext/EntryPointRegistry/customEntryPoint.php
'auth' => true //You need to be authenticated/authorised to perform saves on records
阿賈克斯:
url: 'index.php?entryPoint=takeTicket', //If you check the Sugar docs carefully, you'll see that the URL you need to call is index.php?entryPoint={yourEntryPointRegistryKey}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.