JMJS系统总结系列----Jquery与后台的交互方式(三)

将表单的值通过formSerialize()序列化,然后传递给data,提交给后台处理

var url = "Monitoring.do?action=SaveBanJieInfo";

var formdata = $("#FristPage").formSerialize();

$.ajax({

url: url,

type: "POST",

cache: false,

data: formdata,

success: function(html) {

if (html.indexOf("false") == 0 || html.indexOf("False") == 0){

defineWarmAlert("保存失败!", false);

}

if (html.indexOf("true") == 0 || html.indexOf("True") == 0) {

definealert("保存成功!", false);

}

else {

var msg = html.substring(6);

}

},

error: function(xmlhttprequest, textstatus, errorthrown) {

defineWarmAlert("error!", false);

}

});

将数据在url中传递给后台处理

var ajaxUrl = "Accept.do?action=GetAcceptNumber&IsAccept=" + IsAccept + "&ReceiptNumber=" + ReceiptNumber + "&NoAcceptNumber=" + NoAcceptNumber;

$.ajax({

url: ajaxUrl,

cache: false,

success: function(html) {

if (IsAccept == 1) //已受理

{

document.getElementById("ReceiptNumber").innerText = html;

document.getElementById("Accept/ReceiptNumber").value = html;

}

else if (IsAccept == 2) //不受理

{

document.getElementById("NoAcceptNumber").innerText = html;

document.getElementById("Accept/NoAcceptNumber").value = html;

}

},

error: function(xmlhttprequest, textstatus, errorthrown) {

defineWarmAlert("error!", false);

}

});

通过post表单的方法,将数据提交到后台处理

$(document).ready(function() {

initSkin();

//定义JQuery.from框架的参数

var options = {

url: "Attachment.do?action=UploadProjectImg",

//async: false,

cache: false,

type: 'POST',

beforeSubmit: function() {

var FileName = document.getElementById("Attachment/FileName").value;

if(FileName == null || FileName == "")

{

defineWarmAlert("文件路径不能为空!", false);

return false;

}

else

$.blockUI();

},

success: function(html) {

$.unblockUI();

art.dialog(

{

skin:'chrome',

content:"上传成功!",

lock: true,

style: 'succeed'

} ,

function() {

window.parent.dialogArguments.refreshStep();

window.close();

}

);

return false;

},

error: function(xmlhttprequest, textstatus, errorthrown) {

$.unblockUI();

defineWarmAlert("error", false);

},

dataType: "html"

}

//为提交AddAttachmentForm表单做准备

$("#AddAttachmentForm").ajaxForm(options);

});

在document的ready函数中,使用ajaxForm来为AJAX提交表单进行准备。提交动作必须由submit开始

通过jQuery.get()与后交互,获取后台的返回的数据

jQuery.get(url, [data], [callback], [type])

function getGetApplyCategorys() {

var selectCondi = $("#selectAcceptCondition"); //普通查询

var selectcondi2 = $("#ApplyCategory"); //高级查询

$.get("Accept.do?action=GetApplyCategorys&dt=" + new Date().getTime(), function(str) {

var categoryList = str.split(",");

for (i = 0; i < categoryList.length; i++) {

var data = categoryList[i].split("-");

var item = new Option(data[1], data[0]);

var item2 = new Option(data[1], data[0]);

if (selectCondi.length == 1)

selectCondi[0].options.add(item);

if (selectcondi2.length == 1 && selectcondi2[0].options != null)

selectcondi2[0].options.add(item2);

}

});

}

转载于:https://www.cnblogs.com/lanchong/archive/2011/08/30/2159903.html

你可能感兴趣的:(JMJS系统总结系列----Jquery与后台的交互方式(三))