The path to learning java pain [12] JSON + ajax + Servlet JSON data conversion and transmission, ajaxjson
1. First the client needs to introduce jquery-1.11.1.js
2, followed by javaweb project needs to introduce jar package [commons-beanutils-1.8.0.jar, commons-collections-3.1.jar, commons-lang-2.4.jar, commons-logging-1.1.3.jar, ezmorph-1.0.6.jar]
3. Client js Code
4. servlet server, mapped path CardColl
The above is the entire process. If you have better ideas, you can discuss them together.
The backend uses Servlet to get the JSON from Ajax and then sends it to the backend. How can this problem be solved?
The json file passed to the background is incorrect. You are passing xml.
Json should be: data = {'msg ': {'fromusername': 'erbao', 'tousername': 'me', 'msgtype': 'Hello! '}};
Splice a json string in the background to your success method and parse it with eval (data.
Check your code and you will return "{'result': 1}" in the background. Success Method:
Data = eval (data );
If (data. result = 1 ){}
Servlet + ajax + jquery + json
This is because the bean contains the Date Field and the data read from the database is java. SQL. date is assigned to java. util. date, an error occurred when converting to JSONArray; just convert it when the data is queried.
You can also learn how to copy the error message directly to google after an error is reported, so it is easy to find the answer.