首页 > 代码库 > sell--前台传输数据到后台的几种方式

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="http://www.mamicode.com/

 

// 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}")

 

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