How else to do it?

Asked

Viewed 35 times

0

I am getting this error when I try to upload data to the page via Ajax. There is another way to send Json objects from Servlet to JSP without using document.write? error: "A parser-blockingis invoked via document.write."

Servlet:

private void recuperarValores(final HttpServletRequest request, final HttpServletResponse response) 
            throws IOException, Exception {              

            request.setCharacterEncoding("UTF-8");              
            response.setContentType("application/json");   
            PrintWriter out = response.getWriter();  

         JSONArray jsonArray = new JSONArray();
         JSONObject responseObj = new JSONObject();
        try{
            Escala_DAO e = new Escala_DAO();
        List<Escala> procedimentos = e.GetEscalaTotal("2018-01-01", "2018-01-31");

                     for (Escala obj : procedimentos) {
                         JSONObject js = new JSONObject(); 

                          js.put("jsRe", obj.getRe()); 
                          js.put("jsEntra",obj.getEntrada());                       
                          jsonArray.put(js);

                          }  
                     responseObj.put("jsonArray", jsonArray);
                     out.print(responseObj);                     

                 } catch (JSONException e) {  
        }

    }

JSP:

$.ajax({
                     dataType:'json',
                     url : './GetValores',
                     type : 'POST',                 

                    success: function(data) {

                        queryObject = eval('(' + JSON.stringify(data) + ')');
                        queryObjectLen = queryObject.jsonArray.length;
                        for(var i=0;i<queryObjectLen;i++){ 

                    var inicio = +new Date(queryObject.jsonArray[i].jsEntra);
                    var fim = +new Date(queryObject.jsonArray[i].jsSai);
                    var content = "Jovani";               

                   dados.push({
                                'start': inicio,
                                'end': fim,  
                                'content': content,
                                 'className': 'green'});              

                }

            },
                    error: function() {
                        alert("Ocorreu um erro na requisição ajax");
                    }
                });
  • Where would the document.write?

1 answer

1

After researching a lot I discovered that the problem of document.write:

erro do depurador

was due to two google links that needed to be updated.

What I used to use:

 <script type="text/javascript" src="http://www.google.com/jsapi"></script>
 google.load("visualization", "1", {packages:["corechart"]});

Solution: replace the above links with:

<script type="text/javascript" 
src="https://www.gstatic.com/charts/loader.js"></script>

google.charts.load('current', {'packages':['corechart']});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.