ajax传递多个参数具体实现

2016-02-19 09:39 5 1 收藏

今天图老师小编给大家精心推荐个ajax传递多个参数具体实现教程,一起来看看过程究竟如何进行吧!喜欢还请点个赞哦~

【 tulaoshi.com - Web开发 】

代码如下:

!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
html xmlns="http://www.w3.org/1999/xhtml"
head
title/title
script src="js/Jquery1.7.js" type="text/javascript"/script
script type="text/javascript"
$(function () {
$('#Button1').click(function () {
var username = $('#txtUserName').val();
var pwd = $('#txtPwd').val();
$.ajax({
type: "post",
contentType: "application/json",
url: "WebService1.asmx/Login",
data: "{username:'" + username + "',pwd:'" + pwd + "'}",
success: function (bukeyi) {
if (bukeyi.d == 'true') {
window.location = 'HTMLPage1.htm';
}
else {
$('#divinfo').text("用户名或密码错误");
}
}
})
})
})
/script
/head
body
用户名input id="txtUserName" type="text" /br /
密码input id="txtPwd" type="text" /br /
input id="Button1" type="button" value="登录" /br /
div id="divinfo"/div
/body
/html

------WebService1.asmx----
代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace ajax11
{
/// summary
/// WebService1 的摘要说明
/// /summary
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
[System.Web.Script.Services.ScriptService]
public class WebService1 : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
[WebMethod]
public string ValidateUser(string username)
{
if (username == "onlifes")
{
return "用户名已被占用,请选择其他";
}
else
{
return "可以使用,请继续";
}
}
[WebMethod]
public string GetDate()
{
return DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
}
[WebMethod]
public string Login(string username, string pwd)
{
if (username == "admin" && pwd == "888888")
{
return "true";
}
else
{ return "false"; }
}
}
}

来源:https://www.tulaoshi.com/n/20160219/1591634.html

延伸阅读
标签: Web开发
代码如下: -------------------WebService1 ----------------------------- // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。 [System.Web.Script.Services.ScriptService] public class WebService1 : System.Web.Services.WebService { [WebMethod] public Liststring GetList() { Liststring list = ...
上网的朋友一定都用过网络蚂蚁(Net Ants)的吧?不知你在使用过程中有没有注意过,那就是如果你想调动两个蚂蚁为您效力是不可能的它总会把新运行的关闭。这点在VB中很容易实现: Private Sub Form_Load() If App.PrevInstance Then MsgBox "你已经运行这个应用程序了" End 注释: 退出新运行的程序 ...
标签: Web开发
代码如下: ?xml version="1.0" encoding="UTF-8" ? !DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd" %@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"% %@ page import="java.net.*"% % String location = ""; String location...
       其实这个问题我原来翻译(破除Java神话之二:参数是传址的 )、转帖别人的具体解释(Java 应用程序中的按值传递语义 )和专门解释( 我对《Java 应用程序中的按值传递语义》的理解 )过,不过现在看来,原来翻译或者解释的角度是有问题的,从底层的角度解释并不直观,在交流的时候也轻易引起误...
  客户端 <script language="javascript" //生成XML文件  function GetAllFormData()  {      var strXML = "<Client\r\n<FormData\r\n";      strXML += "<UserNamebccu</UserName"     str...

经验教程

897

收藏

25
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部