Jquery ajax 初探
初学JQUERY AJAX使用,不知道怎么实现,找了半天资料都差不多,可是放到我的页面里就是不返回值,后来发现因为没往后台页面传值的原因,加了 data: "name=John&location=Boston"就好用了,这里data:""可为任意值,后台并没有接收。
下面是例子,实现的是获取服务器时间并更新
前台代码:
function getServerTime()
{
$.ajax({
type: "POST",
url: "Default2.aspx",
data: "name=John&location=Boston",
success: function(msg){
$("#txtserver").text(msg);
}
});
setTimeout('getServerTime()',500);
}
前台代码2:使用Post方法
function getServerTime()
{
$.get("Default2.aspx?1",function(msg){
$("#txtserver").text(msg);});
setTimeout('getServerTime()',500);
}
后台Default2.aspx
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(DateTime.Now.ToLongTimeString());
}
相关文档:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!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 runat=" ......
完全适用ASP.NET的认证机制
–可以使用FormsAuthentication
•WebService方法可以操作Cookie
–Impersonation
–PrincipalPermission
WebService7.cs Code
using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
usi ......
页面文件类似:
<% using (Ajax.BeginForm("AjaxUpdate", 123, new AjaxOptions {
Confirm = "confirm str", LoadingElementId = "idLoading", UpdateTargetId
= "textEntered", OnSuccess = "validateForm" },new{id="idMyForm"}))
&nbs ......
$(function(){
new AjaxUpload('file1', {
action: 'uploadpic.asp',
name: 'form1',
data:{act:'uploadfile',FormName:'form1'},
autoSubmit:false,
responseType:'json',
onSubmit:function(file,ext){
if (!(ext && /^(jpg|png|gif)$/i.test(ext))){
alert('请您上传 ......
jQuery Ajax 全解析
本文短址:http://s8.hk/0itq
<!--
.ajax div{
border: solid 1px red;
}
-->
// <![CDATA[
$(function(){
$("#btnajax").click(function(){
$.ajax({
type: "get",
url: "/rss",
beforeSend: function(XMLHttpRequ ......