sell--前台传输数据到后台的几种方式

1.

//ajax 前提:
$ = $ || {};
$.postJSON = function(url, data) {
    return $.ajax({
        url: url,
        data: JSON.stringify(data),
        dataType:'json',
        contentType: 'application/json; charset=utf-8',
        type: 'post'
    })
};

 

//1. 第一种: <s:url action...
<a href="<s:url action="china-craft-export"/>" class="btn blue" target="_blank">下载中国大货库存 excel</a>
<a href="<s:url action="china-craft-download-template"/>" class="btn blue" target="_blank">下载大货更新模板</a>

//2.第二种: input控件的location
<input type="button" onClick='location="/codelib/log-detail.jhtml?stockLog.id=<s:property value="#log.id"/>"' value="view detail" class="input_btn" />

//3.第三种: form 提交
//3.1
 <form action="/cart/addCart.jhtml" method="post" name="sizelist<s:property value="#productDTO.id" />">....
	<input type="submit" value="" class="input_sub" />

//4.第四种: ajax提交
 	   var param = "calcelOrderId="+id;
	    $.ajax({
	        async:false,
	        data:param,
	        url:"../backoffice/cancelOrder.jhtml",
	        timeout:5000
	    });

//5. 第五种:window.open/ window.location
window.open("/order/invoiceApplicationForm.jhtml?"+params);

 

// coffee
class Model
    searchText: ko.observable('')
    boxes: ko.observableArray()
    info: ko.observable('')
    pageSize: 30
    boxNames: ko.observableArray()
    search: =>
        $.postJSON('/pfizer/search.json', {search: @searchText(), page: 0, pageSize: @pageSize})
        .done (pageResult) =>
            @boxes.removeAll()
            for box in pageResult.result
                box.date = moment(box.createdAt).format('YYYY-MM-DD')
                @boxes.push box
            @info("total: #{pageResult.totalCount}, show: #{@boxes().length}")
        return false
    downloadExcel: =>
        window.open '/pfizer/download-excel.jhtml?_=' + new Date().getTime()
    downloadExcelBox: (box) =>
        tick = new Date().getTime()
        window.open "/pfizer/download-excel-box.jhtml?_=#{tick}&boxId=#{box.id}&boxName=#{box.name}"
    downloadExcelBoxes: =>
        window.open '/pfizer/download-excel-boxes.jhtml?_=' + new Date().getTime()
    showBox: (box) =>
        window.open "/pfizer/edit-box.jhtml?boxId=#{box.id}&searchText=#{@searchText()}"
    loadBox: =>
        boxId = +$('#chooseBox').val()
        if boxId
            $.postJSON('/pfizer/search.json', {boxId: boxId, page: 0, pageSize: @pageSize})
            .done (pageResult) =>
                @boxes.removeAll()
                for box in pageResult.result
                    box.date = moment(box.createdAt).format('YYYY-MM-DD')
                    @boxes.push box
                @info("total: #{pageResult.totalCount}, show: #{@boxes().length}")

 

posted @ 2016-11-17 09:33  黑土白云  阅读(728)  评论(0编辑  收藏  举报