Unified Ajax Submission package, once and for all good tools (with Cross-domain Processing)

Source: Internet
Author: User
Tags domain server

Directly on the code, the use of the core code is provided at the end

        //---------core key, We love----------//         /**        *  Public: Foundation Support          **/        var G = {             /**             *  Unified Request              *  @parm  url Request Server address, format: "${contextpath }/docmanage/list"              *  @parm  FN callback function, format: function settabletr (data) {for (..) {..}}             *  @parm  parm submitted condition, format: {"name" : "zhangsan", "age": "}            **/  "           request:function  (url,fn,parm)  {                 $.ajax ({                     type:  "post",                       async: false,             url      of         url: url, //request                dataType:  "json ",                     data: parm,                      //dynamic execution of this callback function                      success: function  (data)  {                          if (fn!=undefined) fn (data);                     },                     error:function (reslt) {                          alert ("server, Request Failed. ");                     }             })             }         }

Cross-domain request , use the following paragraph of

Unified Request Function request (url,params, fn)  {    $.ajax ({         type:  "get",  //jquey is not supported for post mode across domains          async: false,        url: url, //cross-domain Request URL         dataType:  "jsonp",       The   //is passed to the request handler to obtain the parameter name of the JSONP callback function name (default: Callback)         jsonp:   "callback",        data: params,     After     //successfully obtains the JSON data on a cross-domain server, This callback function is executed dynamically          success: function  (data)  {             var result = data.result;             if  (data.head !=  ' SUCCESS ')  {                 alert ("server error, Please contact the developer in time!");                 return;             }                         if (fn!= Undefined)  FN (result);         }    });


How to Use:

Request ("http://www.baidu.com", {"money": "100000"},moneycall);

function Moneycall (data) {

Alert (json.stringify (data));

}

Unified Ajax Submission package, once and for all good tools (with Cross-domain Processing)

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.