The method of Ajax value-Transfer in JS

Source: Internet
Author: User
Tags browser cache

Way One:

$.post ('.. /ajax/goodsajax.ashx?cmd=getgslist ', function (result) {
   var result = eval (' (' + result + ') ');
   if (result.rbool) {
      $ (' #creatLi '). HTML ("");
      var li = "";
     //dynamically add product category Styles
    $.each (result.flist, function (f, fsort) {//Traversal collection
        Li + = "<li><a class=\" easyui-linkbutton\ "data-options=\" iconcls: ' Icon-folder_page ', plain: True\ ">" + fsort.gs_name + "</a><ul>";
        $.each (result.clist, function (c, csort) {
            IF (fsort.gs_id = = csort.gs_pid) {
               li + = "<li><a class=\" easyui-linkbutton\ "Data-optio Ns=\ "Iconcls: ' Icon-page ', plain:true\" onclick=\ "Getgs (" + csort.gs_id + ") \" > "+ csort.gs_name +" </a></li& gt; ";

}
});
Li + = "</ul></li>";
});

Way Two: (Form submission)

$ (' #fm5 '). Form (' Submit ', {
URL: '.. /ajax/goodsajax.ashx?cmd=addgs ',
Success:function (data) {
var data = eval (' (' + data + ') ');
if (Data.rbool) {
$ ("#GSortWin"). Dialog ({
Closed:true
});

});

Way three:

var title=$ ("#tb1"). Val ();

var contents=$ ("#tb2"). Val ();

$.ajax ({type: "Post", DataType: "Josn",

Data:{jian:title,jian2:contents},

Success:function (data) {if (data.result== "0" {alert ("Add Failed"),} else{alert ("Add Success"),},

Error:function (data) {alert ("error");}

});

URL-pass Multi-parameter mode:

$.ajax ({
URL: "comment_ajax.asp?id=" +number_id+ "&vote_number=" +good_bad,//URL address to submit by default Get method
async:true,//default settings, all requests are asynchronous requests
Cache:false,//set to False will not load the request information from the browser cache.
DataType: ' text ',//data type
Error callback function
Error:function (XHR) {
Alert (' ERROR: ' + xhr.responsetext);
},
Success:function (data) {
callback function after successfully fetching data
Alert (' correct: ' +va);//
$ (' #textfield2 '). val (data);

}

});

Post Parameters:

  1. $.ajax ({
  2. Type: "POST",
  3. URL: ".. /order/ordercancel.action ", //ordermodifystatus
  4. Data: {"orderId": OrderId,"commant": commant},
  5. DataType:"JSON",
  6. Async:false,
  7. Cache:false,
  8. Success: function (data) {
  9. var member = eval ("(" +data+")"); //Packet data parsing to JSON format
  10. if (member.success=="true") {
  11. Flag = true;
  12. }Else if (member.success=="false") {
  13. alert (member.info);
  14. }
  15. },
  16. Error: function (JSON) {
  17. Alert ("Order cancellation exception, please refresh and try again ...");
  18. }
  19. });

The method of Ajax value-Transfer in JS

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.