Discusses. Get. Post. Ajax Ztree and background servlet pass data related knowledge _ajax related

Source: Internet
Author: User

Servlet passes data string to foreground

The method used is

PrintWriter out = Response.getwriter ();
    Response.sendredirect ("test.jsp");
    String s = "[{' id ': ' 1 ', ' pId ': ' 0 ', ' name ': ' test1 '},{' id ': ' One ', ' pId ': ' 1 ', ' name ': ' test11 '}, {' id ': ' A ', ' pid ': ' 1 ', ' Name ': ' test12 '}, {' id ': ' A ', ' pId ': ' One ', ' name ': ' test111 '},] ';
    Out.write (s);

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

About. Get. Post. The plain understanding of Ajax is that

The last one is asynchronous, the front two are synchronized (blocked)

. Get (Url,data,function (data,status) {
execute function
//I understand the data and URL parameters mean the same
})

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

Use of Ztree:

Notice the difference in the format of the two JSON ztree, often using a simple format that shows the structure of the tree directly through the relationship between the data

The second way is through JSON's runaway implementation.

Note that the style and JS file must be introduced in full then the position on the interface is UL

Then it was

Note that the message is passed response the type being passed back is string, which is the method of the String transformation Object
var ss = eval ("(" + Data + ")");
        var t = $ ("#test");
Then is the initialization of the tree control (position, configuration, data)
        t = $.fn.ztree.init (t, setting, SS);
Gets the tree object and then operates
var ztree = $.fn.ztree.getztreeobj ("test");

Collect and collate the data from the backstage to the front desk to solve the problem

About

. Get replaces

. 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 method of passing data to the background servlet using the Post method

<script type= "Text/javascript" >//Statistics resource access number of scripts//Definitions XMLHttpRequest object Var Http_request=false;
   function Send_request (url,rewriteurl) {http_request=false; Starts initializing the XMLHttpRequest object if (window).
     XMLHttpRequest) {//mozilla and other browsers initialize the XMLHttpRequest process http_request=new XMLHttpRequest ();
     Some versions of Mozilla browsers can make mistakes when processing server-returned content 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 initialization xmlhttprequest process try{http_request=new activexobject ("msxml2.xmlhttp");
       catch (e) {try{http_request=new ActiveXObject ("Microsoft.XMLHTTP");
     catch (e) {}}}//exception, create object failed if (!http_request) {Window.alert ("Cannot create XMLHttpRequest object instance!");
   return false;
   }//Specify response handler function http_request.onreadystatechange=processrequest;
   Send HTTP request Information Http_request.open ("POST", url,true); Http_request.setrequesTheader ("Content-type", "application/x-www-form-urlencoded"); Put the parameters here, the background servlet can use the Request.getparameter () method to fetch these parameters http_request.send ("rewriteurl=" + Rewriteurl "&
 Rewriteurl2= "+ rewriteUrl2); //Process return information function ProcessRequest () {//Judge object state if (http_request.readystate==4) {//Judge HTTP status code if (http_req) UEST.STATUS==200) {//information has been successfully returned, no action} else {//Request page has 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 overridden link on the page where the resources are placed}//Statistics js--end access times </script>

In addition, the element that places the rewrite address on the page needs to call the Dosearch (Rewriteurl) method above, passing the overridden link as a parameter to the 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/'); " > China Knowledge Net </a>
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.