Explore. get. post. ajax ztree and background servlet data transmission knowledge,

Source: Internet
Author: User

Explore. get. post. ajax ztree and background servlet data transmission knowledge,

Servlet transmits data strings to the foreground

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);

----------------------

A 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) {executed function // The data and url parameters I understand mean the same })

-------------------------

Use of ztree:

Note the differences between the two json formats of ztree. The common format is that the structure of the tree is displayed directly through the relationship between data.

The second method is implemented through json escape.

Note that styles and js files must be fully introduced, followed by ul on the interface.

Then

// Note that the type passed by response is string, which is the method of string Conversion object var ss = eval ("(" + data + ")"); var t = $ ("# test"); // then the initialization of the tree control (location, configuration, data) t = $. fn. zTree. init (t, setting, ss); // get the tree object and then operate var zTree = $. fn. zTree. getZTreeObj ("test ");

Collect and sort out the background data to the front-end to solve the problem

About

Replace. get

.ajax $("button").click(function(){ $.get("demo_ajax_load.txt", function(result){  $("div").html(result); });});------------ $.ajax({ url: url, data: data, success: success, dataType: dataType }); 

Ps: AJAX uses the POST method to transmit data to the backend Servlet

<Script type = "text/javascript"> // script used to count resource access times // defines the XMLHttpRequest object var http_request = false; function send_request (url, rewriteUrl) {http_request = false; // start initializing the XMLHttpRequest object if (window. XMLHttpRequest) {// process http_request = new XMLHttpRequest (); // some versions of Mozilla may encounter errors when processing content returned by the server that does not contain the XML mime-type header. // Therefore, make sure that the returned content contains text/xml Information. if (http_request.overrideMimeType) {http_request.over RideMimeType ("text/xml") ;}} else if (window. activeXObject) {// try {http_request = new ActiveXObject ("Msxml2.XMLHTTP");} catch (e) {try {http_request = new ActiveXObject ("Microsoft. XMLHTTP ");} catch (e) {}} // exception. if (! Http_request) {window. alert ("You cannot create an XMLHttpRequest object instance! "); Return false;} // specify the response processing function http_request.onreadystatechange = processRequest; // send the HTTP Request Information http_request.open (" POST ", url, true ); http_request.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded"); // put the parameter here, And the backend servlet can use request. the getParameter () method obtains these parameters http_request.send ("rewriteUrl =" + rewriteUrl "& rewriteUrl2 =" + rewriteUrl2);} // process the returned information function processRequest () {// determine the object status if (http_requ Est. readyState = 4) {// determine the HTTP status code if (http_request.status = 200) {// information has been returned successfully, no action} else {// The request page has a Problem alert ("the page you requested has an exception! Error status: "+ http_request.status) ;}} function dosearch (rewriteUrl) {send_request (" http://127.0.0.1:8000/ ); // The rewriteUrl here is the rewritten link of the resources placed on the page} // JS -- end for counting the number of resource accesses </script>

In addition, the elements that place the rewrite address on the page need to call the above dosearch (rewriteUrl) method and pass the rewritten link as a parameter to this method. For example:

<A href = "http: // 127.0.0.1: 8000/iras50/rewriter/CNKI/" target = "_ blank" onclick = "dosearch ('HTTP: // 127.0.0.1: 8000/iras50/rewriter/CNKI/'); "> chinnet </a>
Articles you may be interested in:
  • Jquery zTree asynchronous loading simple instance sharing
  • Jquery ztree uses json data in the drop-down tree.
  • Summary of common methods for submitting post and post using ajax data in php
  • Ci checks whether ajax or page post submits data
  • Example of ajax post () method usage in jQuery
  • Details about Ajax get and post methods in jQuery
  • How to obtain data from all selected nodes using the js tree plug-in zTree
  • Getting started with Jquery tree plug-in zTree

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.