JQuery错误尝试使Ajax调用
问题描述:
我正在处理SharePoint项目。我想使用JQuery从主页进行ajax调用。但是,当我拨打电话时,我得到“Array.prototype.slice:'this'不是JavaScript对象”错误。JQuery错误尝试使Ajax调用
下面是我使用的文件的广告代码: homepage.js/
$(document).ready(function() {
Ajax.GetWeather();
});
Ajax.js/
ns.GetWeather = function() {
alert("yep");
$.ajax({
data: $.extend({
Function: "GetWeather"
}),
type: 'POST',
success: function (json) {
//$('#ContentMain').append(json.LoginMainHtml);
//$('#ContentSide').append(json.LoginSideHtml);
alert("hmmmm");
ns.HideUpdateStatus();
}
});
};
14/TEMPLATYS /设计/ GWR /阿贾克斯。 ASHX/
<%@ WebHandler Language="C#" Class="ajax" %>
using System;
using System.Reflection;
using System.Web;
/**
* Ajax.ashx
*
* Enables client callback resource to client javascript.
* Functions are relayed to DataManager for processing.
*/
public class ajax : IHttpHandler
{
/// <summary>
/// Processes the client request
/// </summary>
public void ProcessRequest (HttpContext context)
{
// Set the content type so the client's browser will handle the response correctly
context.Response.ContentType = "text/json";
// Get the function name from the request GET/POST parameters
string function = context.Request["Function"];
context.Response.Write(function);
}
}
DataManager.cs/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Script.Serialization;
using System.Web;
namespace GWR
{
class DataManager: Util
{
#region Properties
/// <summary>
/// Accesses the Request object
/// </summary>
private static HttpRequest Context
{
get { return HttpContext.Current.Request; }
}
#endregion
#region GetWeather
public static string GetWeather()
{
return ToJson(new
{
//LoginSideHtml = RenderUserControl("LoginSide.ascx", null),
//LoginMainHtml = RenderUserControl("LoginMain.ascx", null)
AlertHTML = "<h1>Got Here Alert Weather</h1>",
CurrentHTML = "<h2>Got here current weather",
FiveDayHTML = "<h3>5 day forcast</h3>"
});
}
#endregion
#region ToJson
/// <summary>
/// Converts an object into JSON compatible form
/// </summary>
/// <param name="o"></param>
/// <returns></returns>
public static string ToJson(object o)
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
return serializer.Serialize(o);
}
#endregion
}
}
答
此:
data: $.extend({
Function: "GetWeather"
})
应该是:
data: $.extend({},{
"Function": "GetWeather"
})
或:
data: {"Function":"GetWeather"}
或:
data: "Function=GetWeather"
谢谢,这就是它 – user1231748 2012-07-09 16:00:01
@ user1231748如果它的工作,那么可能你可以[接受](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work )它。 – Engineer 2012-07-09 17:27:29