JS異步同步方法


//URL參數獲取ajax

function GetQueryString(sProp) {json

    varre = new RegExp("[&,?]"+ sProp + "=([^\\&]*)", "i");dom

    vara = re.exec(document.location.search);異步

    if(a == null)async

        return"";ide

    returna[1];url

spa

 

/*get

* 同步反回參數同步

* url 鏈接地址

* param 參數 json格式

* timeout 超時時間(毫秒)

*/

var ajaxSynchronous = function(url, param,timeout) {

    vartemp = {};

    $.ajax({

        type: "POST",

        url: url,

        data: param,

        async: false,

        timeout: timeout,

        success: function(msg) {

            temp = msg;

        }

    });

    returntemp;

}

/*

*異步請求方法

* url 鏈接地址

* param 參數 json格式

* fn_success 成功後執行

*/

var ajaxAsynchronous = function(url, param,fn_success) {

    $.ajax({

        type: "POST",

        url: url,

        data: param,

        async: true,

        timeout: 3000,

        success: fn_success

    });

}

var params ={};

params.async = 6;

params.flag = "affixup";

params.random = new Date().getTime();

params.affixType=affixType;

varvdata = ajaxSynchronous("../AjaxPage/AJAX_GetDataPage.aspx",params,3000);

vartemp = $.trim(vdata);

vararr = temp.split("|");

//var dtemp =eval('('+temp+')');  var rows =dtemp.mattype;

if(arr != null && arr.length > 1){

   if(arr[0]== "error") {

        alert("請上傳附件!");

        return;

   }

}

相關文章
相關標籤/搜索