parms 參數統一 json格式的數據
url 訪問后台的url
設置同步參數
- $.ajaxSetup({ async : false}); // 同步參數 false為同步,tree為異步
第一種:
Get方式
- $.get("url", parms, function(data, status) {
- if (status == "success") {
- data = eval("(" + data + ")");
- aDataSet = data;
- alert("data is " + aDataSet);
- } else {
- alert("wrong");
- }
- });
Post方式
1 <span style="font-size:18px;"> 2 $.post("url", params, function (data) { 3 $("#BoxBottleId").val(data); 4 }); 5 </span>
第二種:
LigerUI中的 getJSON
<span style="font-size:18px;">
$.getJSON('url?ajaxaction=GetClassProductByFid&FatherId=' + currentid,
function (json) { gridRight.set('data', json); //把json塞到下拉框里面去 });
</span>
第三種:
ajax方式:
<span style="font-size:18px;">
url (String) : 請求的HTML頁的URL地址。 data (Map) : (可選參數) 發送至服務器的 key/value 數據
</span><span style="font-size:18px;">
$.ajax({ cache: false, async: true, url:'../handle/baseinfo.ashx?ajaxaction=GetClassProductByFid', // 后台取 data: p.data, dataType: 'json',
type: 'post', beforeSend: function () { LG.loading = true; if (p.beforeSend) p.beforeSend(); else LG.showLoading(p.loading); }, complete: function () { LG.loading = false; if (p.complete) p.complete(); else LG.hideLoading(); }, success: function (result) { p.success(result); }, error: function (result, b) { LG.tip('發現系統錯誤 <BR>錯誤碼:' + result.status); } }); </span><span style="font-size:18px;">
$.ajax({ cache: false, async: true, dataType: 'json',
type: 'post', url: options.url, data: { view: options.view, idfield: options.idfield, textfield: options.textfield, where: JSON2.stringify(where) }, success: function (data) { if (!data || !data.length) return; g._changeValue(data[0]['id'], data[0]['text']); } });
</span>
第四種:
LigerUI:
<span style="font-size:18px;"> LG.ajax({ loading: '正在加載數據...', url: '../handle/IdBoxKey.ashx?ajaxaction=GetBoxKeyByApplyId&ApplyId=' + applyid, success: function (result) { grid1.set('data',result); }, error: function (message) { LG.tip(message); } }); </span>
