下面的arguments[0]什么意思?
$.ajax({
url:"Comment.aspx?action=ajax_sendcomment&commentparentid="+$CommentParentID+"&commentuser="+escape($CommentUser)+"&commenttext="+escape($CommentText)+"&commentvalidate="+escape($CommentValidate)+"&time="+new Date().toString(),
type:'GET',
success:function(){
if (arguments[0]=='ERROR')
{
alert('验证码出错!');
}
else{
GetComment($CommentParentID,1);
alert(arguments[0]);
$("#CommentText").val("");
//验证成功时,刷新验证码图片
$("#CommentValidateImages").attr("src","VerifyCode.aspx?s="+Math.random());
}
$("#CommentValidate").val("");
}
});
$.ajax({
url:"Comment.aspx?action=ajax_sendcomment&commentparentid="+$CommentParentID+"&commentuser="+escape($CommentUser)+"&commenttext="+escape($CommentText)+"&commentvalidate="+escape($CommentValidate)+"&time="+new Date().toString(),
type:'GET',
success:function(){
if (arguments[0]=='ERROR')
{
alert('验证码出错!');
}
else{
GetComment($CommentParentID,1);
alert(arguments[0]);
$("#CommentText").val("");
//验证成功时,刷新验证码图片
$("#CommentValidateImages").attr("src","VerifyCode.aspx?s="+Math.random());
}
$("#CommentValidate").val("");
}
});
function test(a,b,c,d){
alert(arguments[0]);
}arguments[0]实际上就是a,同理,arguments[1]就是b,依次c,d
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using _211;
using System.Threading;/// <summary>
/// Comment 的摘要说明
/// </summary>
public partial class Comment : System.Web.UI.Page
{
string action = string.Empty;
string id = string.Empty;
string page = string.Empty;
string pagehtml = string.Empty;
string linkhtml = string.Empty;
int Pages = 5; string commentparentid = string.Empty;
string commentuser = string.Empty;
string commenttext = string.Empty;
string commentvalidate = string.Empty;
public Comment()
{
//
// TODO: 在此处添加构造函数逻辑
//
} protected void Page_Load(object sender, EventArgs e)
{
Thread.Sleep(5000);
action = Request.Params["action"];
id = Request.Params["id"];
page = Request.Params["page"];
commentparentid = Request.Params["commentparentid"];
commentuser = Request.Params["commentuser"];
commenttext = Request.Params["commenttext"];
commentvalidate = Request.Params["commentvalidate"];//51^aspx if (action == "ajax_getcomment")
{
ajax_getcomment(id, Int32.Parse(page));
}
else if (action == "ajax_sendcomment")
{ if (Session["VerifyCode"].ToString().ToLower() != commentvalidate.ToLower())
{
Response.Write("ERROR!"); }
else
{
DBQuery.ExecuteScalar("insert into comment(commentparentid,commentuser,commenttext,commentreply,commentip) values('" + commentparentid + "','" + commentuser + "','" + Server.HtmlEncode(commenttext) + "','','" + Request.ServerVariables["REMOTE_ADDR"] + "')");
Response.Write("评论发表成功!");
}
}
else
{
Response.Write("error!");
} }
private void ajax_getcomment(string id, int page)
{ using (CommentBO cm = new CommentBO(id, page - 1))
{
Response.Write(cm.getCommentContent());
}
}}
但它的类型是object. 可通过下标访问其中元素,也可通过length获得个数arguments 与 js 函数定义的 参数无关, 无论你是否定义参数,都可传递任意个参数。arguments[0] 就是 获取第一个参数
success:function(){
if (arguments[0]=='ERROR')
{
alert('验证码出错!');
}
函数的规范写法是
success:function(responseText){
if (responseText=='ERROR')
{
alert('验证码出错!');
}
}因为 success 后的函数 在响应成功返回后 会被调用 并传递一个参数(responseText)也就是返回的响应文本 ,所以你 success 后的函数 不定义参数 它还是会传递 这个时候想要访问传递的参数 就需要用 arguments[0]
该对象代表正在执行的函数和调用它的函数的参数。[function.]arguments[n]参数
function可选项。当前正在执行的 Function 对象的名字。n必选项。要传递给 Function 对象的从0开始的参数值索引。说明
不能显式创建 arguments 对象。arguments 对象只有函数开始时才可用。函数的 arguments 对象并不是一个数组,访问单个参数的方式与访问数组元素的方式相同。索引 n 实际上是 arguments 对象的 0…n 属性的其中一个参数。示例
下面的示例演示了 arguments 对象的用法。function ArgTest(a, b){
var i, s = "The ArgTest function expected ";
var numargs = arguments.length; // 获取被传递参数的数值。
var expargs = ArgTest.length; // 获取期望参数的数值。
if (expargs < 2)
s += expargs + " argument. ";
else
s += expargs + " arguments. ";
if (numargs < 2)
s += numargs + " was passed.";
else
s += numargs + " were passed.";
s += "\n\n"
for (i =0 ; i < numargs; i++){ // 获取参数内容。
s += " Arg " + i + " = " + arguments[i] + "\n";
}
return(s); // 返回参数列表。
}