我从控制器中的数据库中获取此数据。我在检索数据时使用了adslashes而保存和stropslashes。请参阅控制器和php文件。我需要修复此错误。我希望有人能说出我做错了什么。
{"records":[{"id":"425","name":"a","content":"a\b<br>a<br>b"},{"id":"426","name":"1","content":"1\2"}]}
另外请检查.. ionicnotepad.com/www这是我正在练习制作。如果您在中断数据时保存数据..无论在textarea中显示什么内容都是正确的。我尝试了一切。 $ sce,ng-bind-html,ng-sanitize,甚至是指令,如果你使用div和conteneditable。
//controller
app.value('count', 0);
app.controller('retrieveController', ['$sce','noteRetrieve','$state','alterNote','count','$ionicModal','$scope', function($sce, noteRetrieve, $state, alterNote, count, $ionicModal, $scope){
var controller = this;
var temp = localStorage.getItem("ascOrDsc");
if(temp == "asc" || temp == null){
controller.orderValue = 'id';
controller.buttonDown = false;
controller.buttonUp = true;
localStorage.setItem("ascOrDsc", "asc");
} else {
controller.orderValue = '-id';
controller.buttonUp = false;
controller.buttonDown = true;
}
noteRetrieve.all()
.success(function(data){
var newData = data.replace(/<br>/g, '<br>');
newData = newData.substring(1, newData.length - 1);
// newData = angular.fromJson(newData);
console.log(newData);
// controller.allSaved = newData.records;
// for(i = 0; i < newData.records.length; i++){
// count++;
// }
// controller.noOFNotes = count;
});
controller.deleteNote = function(noteId, noteName, noteContent){
var currentNote = {
id: noteId,
name : noteName,
content : noteContent
};
controller.itemId = noteId;
alterNote.delete(currentNote)
.success(function(){
$state.go('notes.allnotes', {}, {reload: true});
});
};
controller.changOrder = function(){
var ascOrDscValue = localStorage.getItem("ascOrDsc");
if(ascOrDscValue == 'asc'){
controller.orderValue = '-id';
controller.buttonUp = false;
controller.buttonDown = true;
localStorage.setItem("ascOrDsc", "desc");
} else {
controller.orderValue = 'id';
controller.buttonUp = true;
controller.buttonDown = false;
localStorage.setItem("ascOrDsc", "asc");
}
};
$ionicModal.fromTemplateUrl('templates/createNote.html', {
scope: $scope,
animation: 'slide-in-up'
}).then(function(modal){
$scope.modal = modal;
});
$scope.createModal = function() {
$scope.modal.show();
localStorage.setItem('newNoteAvailable', 'no');
};
$scope.closeModal = function() {
if(localStorage.getItem('newNoteAvailable') == 'yes'){
$state.go('notes.allnotes', {}, {reload: true});
} else {
$state.go('notes.allnotes', {}, {reload: false});
}
$scope.modal.hide();
$ionicModal.fromTemplateUrl('templates/createNote.html', {
scope: $scope,
animation: 'slide-in-up'
}).then(function(modal){
$scope.modal = modal;
});
};
}]);
//php
$sql = "SELECT *
FROM noteFile";
$result = mysqli_query($conn, $sql);
$outp = "";
while($rs = $result->fetch_array(MYSQLI_ASSOC)) {
if ($outp != "") {
$outp .= ",";
}
$outp .= '{"id":"' . $rs["id"] . '",';
$outp .= '"name":"' . $rs["name"] . '",';
$outp .= '"content":"'. $rs["data"] . '"}';
}
$outp ='{"records":['.$outp.']}';
$outp = json_encode($outp);
// var_dump($outp);
$outp = stripslashes($outp);
echo ($outp);
答案 0 :(得分:1)
部分"content":"1\2"
无效,应为"content":"1\\2"