In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
What is the use of servlet background data transmission in Ajax? many novices are not very clear about this. In order to help you solve this problem, the following editor will explain it in detail. People with this need can come and learn. I hope you can get something.
Servlet passes the data string to the front desk.
The method used is
PrintWriter out = response.getWriter (); / / response.sendRedirect ("test.jsp") String s = "[{'id':'1',' pId':'0', 'name':'test1'}, {' id':'11', 'pId':'1',' name':'test11'}, {'id':'12',' pId':'1', 'name':'test12'}, {' id':'111', 'pId':'11',' name':'test111'},]" Out.write (s)
--
The simple understanding of .get .post .ajax is
The last one is asynchronous, and the first two are synchronous (blocking)
.get (url,data,function (data,status) {function executed / / I understand that the data and url parameters mean the same})
-
Use of ztree:
Note the difference between the two json formats of ztree. The simple format is often used to show the structure of the tree directly through the relationship between the data.
The second is achieved through the absconding of json.
Note that the style and js files must be imported, and then the location on the interface is ul.
And then
/ / Note that the type passed back by response is string, which is the string transformation object method var ss = eval ("(" + data + ")"); var t = $("# test"); / / then tree control initialization (location, configuration, data) t = $.fn.zTree.init (t, setting, ss); / / get the tree object and then manipulate var zTree = $.fn.zTree.getZTreeObj ("test").
Collect and organize, solve the problem of transmitting the data from the background to the front desk
About
Replace .get with
.ajax $("button") .click (function () {$.get ("demo_ajax_load.txt", function (result) {$("div") .html (result);});});-$.ajax ({url: url, data: data, success: success, dataType: dataType})
The method that ps:AJAX uses the POST method to pass data to the background Servlet
/ / script to count the number of resource visits / / define XMLHttpRequest object var http_request=false; function send_request (url,rewriteUrl) {http_request=false; / / start initializing XMLHttpRequest object if (window.XMLHttpRequest) {/ / Mozilla and other browsers initialize XMLHttpRequest process http_request=new XMLHttpRequest (); / / some versions of Mozilla browsers will make errors when dealing with content returned by the server that does not contain XML mime-type header information. / / therefore, make sure that the returned content contains text/xml information. If (http_request.overrideMimeType) {http_request.overrideMimeType ("text/xml");}} else if (window.ActiveXObject) {/ / IE browser initializes the XMLHttpRequest process try {http_request=new ActiveXObject ("Msxml2.XMLHTTP");} catch (e) {try {http_request=new ActiveXObject ("Microsoft.XMLHTTP") } catch (e) {} / / exception, failed to create object if (! http_request) {window.alert ("cannot create XMLHttpRequest object instance!"); return false;} / / specify response handler function http_request.onreadystatechange=processRequest; / / send HTTP request message http_request.open ("POST", url,true) Http_request.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded"); / / put the parameters here, and the background servlet can get these parameters http_request.send ("rewriteUrl=" + rewriteUrl "& rewriteUrl2=" + rewriteUrl2) using the request.getParameter () method. } / / processing the returned information function function processRequest () {/ / judging the object status if (http_request.readyState==4) {/ / judging the HTTP status code if (http_request.status==200) {/ / the information has been returned successfully, no action} else {/ / request page has a problem alert ("the page you requested is abnormal! Error status: "+ http_request.status);} function dosearch (rewriteUrl) {send_request (" http://127.0.0.1:8000/); / / the rewriteUrl here is the JS--end of the rewritten link of the resource placed on the page} / / the number of resource visits
In addition, the element that places the rewrite address on the page needs to call the above dosearch (rewriteUrl) method, passing the rewritten link as an argument to this method, for example:
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.