-->

XML Parsing Error in Firefox developer console

2020-08-17 18:04发布

问题:

I have a jquery scripts which sends data to a java servlet and updates the content of the page basing on the servlet response. Everything works (the page gets updated with the values as I was expecting), but I can see in the developer console in firefox the following error:

XML Parsing Error: syntax error Location: http://localhost:8080/servlet_url Line Number 1, Column 1

This is my jQuery code:

 <script src="http://code.jquery.com/jquery-1.10.2.js" type="text/javascript"></script>
 <script type="text/javascript">
 $(document).ready(function() {
 $.post('servlet', {
 filepath : '${file}'},
 function(responseText){
 $('#div_id').text(responseText);
 });
 });
 </script>

回答1:

It seems that the issue occurred because I forgot to set the response content type in the servlet. So basically this line of code:

 response.setContentType("text/plain"); 

solved the problem.