2015-07-13 20 views
1

我在使用Angular AJAX保存數據庫中的CKEDITOR值時遇到了問題。我不知道它是一個角度問題還是PHP。順便說一句,我在我的應用程序中使用CodeIgniter 3。如何在Ajax Angular中保存ckeditor值?

這裏有一點我的代碼,我希望你明白,我有:

我CKEDITOR: 在這裏,我保存了協議

這裏的AJAX保存:

$scope.saveContent = function() { 

    $scope.totals = [{ 
     'subtotals' : computeGrandTotal(), 
     'vat_rate' : quoteList.vat_rate, 
     'grandtotal': computePercentage() 
    }]; 

    $http({ 
     url: "<?php echo base_url('index.php/tutorial/submitQuotation'); ?>", 
     method: 'POST', 
     data: $.param({ 
       quotation: $scope.quoteHeader.items, 
       msc: quoteList, //here goes the agreeement content 
       totals: $scope.totals 
      }), 
     headers: {'Content-Type': 'application/x-www-form-urlencoded'} 
    }).success(function(data){ 
     alert('Data successfully inserted!'); 
    }).error(function(){ 
     alert('Error Occured!'); 
    }); 

} 

而在我的模型中,我這樣做:

$sqlInsertQuotationAgreement = "INSERT INTO quotation_agreement SET quoatation_id = " . (int)$quotationID . ", agreement = '" . $agreement . "'"; 
$queryInsertQuotationAgreement = $this->db->query($sqlInsertQuotationAgreement); 

而當我檢查我的開發者控制檯時,我得到一個錯誤,因爲我的CKEDITOR中的值以HTML格式呈現,而不是代碼中。我試圖使用stripslashes()和$ this-> db-> escape(),但仍然錯誤。

你能幫我嗎?

+0

好,我試圖用這個功能,它得到我的HTML數據:'用htmlspecialchars()'但是我得到這個錯誤:'您的SQL語法錯誤;檢查與您的MySQL服務器版本相對應的手冊,以獲得正確的語法,以便在物料和碎石以及機器和設備附近使用,並且通常應該在'1號線' – Jerielle

回答

1

好吧,我解決了我的錯誤。下面是我在查詢中所做的:

$sqlInsertQuotationAgreement = "INSERT INTO quotation_agreement SET quotation_id = " . (int)$quotationID . ", agreement = \"" . htmlspecialchars($agreement) . "\"";