Reputation: 69
I'm getting this data from the database in the controller. I have used adslashes while saving and stropslashes while retrieving data. Please see controller and php file. I need to get this error fixed. I hope someone can tell what I'm doing wrong.
{"records":[{"id":"425","name":"a","content":"a\b<br>a<br>b"},{"id":"426","name":"1","content":"1\2"}]}
Also please check.. ionicnotepad.com/www this is what im practicing making. If you save data with a break in it.. anugular no matter what is showing
in the textarea. I tried everything. $sce, ng-bind-html, ng-sanitize, even the directive if you use divs and 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);
Upvotes: 5
Views: 24147
Reputation: 748
The part "content":"1\2"
is not valid, it should be "content":"1\\2"
Upvotes: 3