Home > front end >  Why always ajax error
Why always ajax error

Time:04-17

This is a servlet
 
import java.io.IOException;
Import the Java. IO. PrintWriter;
import java.util.ArrayList;
import java.util.List;

The import javax.mail. Servlet. ServletException;
The import javax.mail. Servlet. ServletRequestAttributeEvent;
The import javax.mail. Servlet. The annotation. WebServlet;
The import javax.mail. Servlet. HTTP. HttpServlet;
The import javax.mail. Servlet. HTTP. It;
import javax.servlet.http.HttpServletResponse;


The import com. Fasterxml. Jackson. Databind. ObjectMapper;
The import com. Fasterxml. Jackson. Databind. JsonFormatVisitors. JsonArrayFormatVisitor;

Import JDK. Nashorn. Internal. Runtime. Would the LinkerCallSite;
The import net. Sf. Json. JSONArray;

/* *
* the Servlet implementation class Process
*/
@ WebServlet ("/Process ")
Public class Process extends the HttpServlet {
private static final long serialVersionUID=1L;

/* *
* @ see HttpServlet# HttpServlet ()
*/
Public Process () {
super();
//TODO Auto - generated constructor stub
}

/* *
* @ see HttpServlet# doGet (it request, HttpServletResponse response)
*/
Protected void doGet (it request, HttpServletResponse response) throws ServletException, IOException {
//TODO Auto - generated method stub
//response. GetWriter (). Append (" Served at: "), append (request) getContextPath ());
//the doPost (request, response);

}

/* *
* @ see HttpServlet# doPost (it request, HttpServletResponse response)
*/
Protected void doPost (it request, HttpServletResponse response) throws ServletException, IOException {
//TODO Auto - generated method stub
//doGet (request, response);
List List=new ArrayList (a);
List. The add (new test (20, 1));
List. The add (new test (10, 2));
List. The add (new test (30, 3));
List. The add (new test (25, 4));
List. The add (new test (50, 5));
List. The add (new test (5, 6));
List. The add (new test (15, 7));

//ObjectMapper mapper=new ObjectMapper ();//Java - json transformation class
//String json=mapper. WriteValueAsString (list);
//System. Out. Println (json);
JSONArray JSONArray=JSONArray. FromObject (list);
The response. GetWriter (). Println (jsonArray);

}

}


This is the front
 
<% @ page language="Java" contentType="text/HTML. Charset=utf-8 "
PageEncoding="utf-8" % & gt;


<meta HTTP - equiv="content-type" Content="text/HTML. Charset=utf-8 "& gt;
Insert the title here
<script SRC="https://bbs.csdn.net/topics/jquery-3.5.1.js" & gt; </script>
<script SRC="https://bbs.csdn.net/topics/echarts.min.js" & gt; </script>

<body>


//based on dom, prepared to initialize ecahrts instance
Var myChart=echarts. Init (document. GetElementById (" graph "));

//specified icon of configuration items and data
MyChart. SetOption={
Title: {
Text: "data visualization"
},
Tooltip: {},
Legend: {
Left: "right,"
Data: [" concentration "]
},
XAxis: {
Data: []
},
YAxis: {},
Series: [{
Name: 'concentration'
Data: []
}]

};
Var XX=[];//x coordinate values
Var YY=[];//y coordinate values

//Ajax data request
$. Ajax ({
Type: "post",
Async: true, asynchronous request//
Url:/Process ", "
Data: {},
DataType: "json",

//request after a successful accept receiving data xtime + yppm two groups of data;
Success: the function (result) {
Alert (" asdsad ")
//result for the server returns a json object
If (result) {
//remove the data storage array
for(var i=0; iXX. Push (result [I]. X);
for(var i=0; iYY. Push (result [I] y);

//cover according to the data load operation data table
MyChart. SetOption ({
XAxis: {data: XX},
Series: [{
//the name: "concentration",
Date: YY
}]
});
}
},
Error: function (errorMsg) {
//request fails to execute the function
Alert (" icon data request failed ");
MyChart. Hideloading ();
}

})


</script>









This is the directory structure
  •  Tags:  
  • Ajax
  • Related