How to sanitize data sent from the server in ajax call ?
I have the following quiz component
here.
There are 10 questions and on click of the result of the final question , your performance of the over all quiz is shown, the response is fetched though a ajax request (in scripts.js) , like so:
- $.ajax({
- type: "POST",
- url: $("#quizForm input#QuizResultPreview").val(),
- dataType: 'html',
- contentType: 'application/json',
- data:JSON.stringify(quizAttempt),
- success: function(data) {
- /* console.log(data);
- var data = JSON.parse(data);
- var html = '';
- for( var i = 0; i < data.length ; i++ ) {
- if( data[i].CorrectSelectionResponse !== null ) {
- html += "<div class='quiz__indi__answerwrapper'><span>"+ data[i].QID.slice(1 , data[i].QID.length ) +"</span><span>"+ strip(data[i].Question) +"</span><span>"+ data[i].CorrectSelectionResponse +"</span></div>";
- } else {
- html += "<div class='quiz__indi__answerwrapper'><span>"+ data[i].QID.slice(1 , data[i].QID.length ) +"</span><span>"+ strip(data[i].Question) +"</span><span>"+ data[i].WrongSelectionResponse +"</span></div>";
- }
- } */
- $('#resultTemp').html(data);
- },
- error: function(xhr) {
- $("#resultTemp").text(xhr);
- $('#resultTemp').show();
- },
- failure: function(xhr) {
- $("#resultTemp").text(xhr);
- $('#resultTemp').show();
- }
- });
In the html though i see a few weird characters displayed
like so (The same can be seen by navigating the quiz component link i shared above). how do i sanitize the data sent from the server ?