zoukankan      html  css  js  c++  java
  • $.ajax()与$.post()区别

    当使用$.ajax时:

    var name = $('#txtUserName').val();

                    var pwd = $('#txtPassWord').val();

                    var param = "{username:'" + name + "',password:'" + pwd + "'}";

                    $.ajax({

                        type: "POST",

                        url: "/Main/DoLogin",

                        data: param,

                        contentType: "application/json;charset=utf-8",

                        success: function (msg)

                        {

                            var test = msg;

                            var test2 = test;

                        },

                        error: function (e)

                        {

                            var test = e;

                            var test2 = test;

                        }

                    });

    当使用$.post时:

    var name = $('#txtUserName').val();

                    var pwd = $('#txtPassWord').val();

                    var param = { username: name, password: pwd };

                    $.post('/Main/DoLogin', param, function (result) {

                        var test = result;

                        alert(test);

                    });

    使用$.ajax时参数要写成JSON字符串的格式,使用$.post是参数要写成JSON对象的格式。

  • 相关阅读:
    java进程自动杀死
    线程池的取值(一)与拒绝策略
    zju 1383 Binary Numbers
    可以连续几行数,,,分别相加求和
    几个数字的和
    zju 2812 Quicksum---------hdu 2734
    rwkj 1332 C语言实验四(函数):题目1、数字根
    zju 1295 Reverse Text
    zju 1241 Geometry Made Simple
    hdu 1379 DNA Sorting
  • 原文地址:https://www.cnblogs.com/Bobo999/p/9453136.html
Copyright © 2011-2022 走看看