• jquey ajax 无刷新提交form


     http://bbs.csdn.net/topics/380237868


    $.ajax({
      type: "POST",   url:ajaxCallUrl,   data:$('#yourformid').serialize(),// 你的formid   async: false,   error: function(request) {     alert("Connection error");   },   success: function(data) {     $("#commonLayout_appcreshi").parent().html(data);   } });

     

    其中用的 jQuery ajax 的函数:

    serialize()  

    返回字符串 :

    "name=tomcruze&password=111&mobile=13911112222&memo=tom+cruze"

    serializeArray()

    生成JSON:

    [

    {"name":"name","value":"tomcruze"},

    {"name":"password","value":"111"},

    {"name":"mobile","value":"13911112222"},

    {"name":"memo","value":"tom cruze"}

    ]

     前一种方便GET提交,后一种方便遍历处理以后再post提交数据。

    遍历方法: http://www.cnblogs.com/zjfree/archive/2011/12/30/2307683.html

    //将form中的值转换为键值对。
    function getFormJson(frm) {
        var o = {};
        var a = $(frm).serializeArray();
        $.each(a, function () {
            if (o[this.name] !== undefined) {
                if (!o[this.name].push) {
                    o[this.name] = [o[this.name]];
                }
                o[this.name].push(this.value || '');
            } else {
                o[this.name] = this.value || '';
            }
        });
    
        return o;
    }

    注意其中,因为this.value的格式问题,js对象用数组的方法。

  • 相关阅读:
    抽象类和构造方法
    JAVA System.arraycopy 和Arrays.copyof 效率比较
    直接插入排序
    StringBuffer
    JButton计数
    冒泡排序法
    JFrame背景
    JButton按钮
    Swing——JFrame
    JFrame面板
  • 原文地址:https://www.cnblogs.com/mitang/p/4168472.html
Copyright © 2020-2023  润新知