JQuery尝试进行Ajax调用时出错
JQuery Error Trying to Make Ajax Call
我正在处理一个SharePoint项目。我想使用JQuery从主页进行ajax调用。然而,当我进行调用时,我会得到"Array.prototype.slice:'this'不是JavaScript对象"错误
以下是我正在使用的文件和代码:主页.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/模板/布局/GWR/Ajax.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"
相关文章:
- 尝试调用AngularJS上的函数时出错
- 从 java 脚本调用函数时 PHP 中出错
- 使用Angular获取数据API调用时出错
- CakePHP错误:在非对象上调用成员函数get(),使用cakejavascript助手时出错
- 在 $.ajax 调用中出错
- AWS:调用getCredentialsForIdentity()时出错
- 404调用jQuery.post时出错
- 要求JS 2.1.9引起“;最大调用堆栈"使用Grunt时出错
- 完成ajax调用数组的循环,而不是在某个调用出错时中断
- 警告:字体加载过程中出错:轨道上的PDFJS超过了最大调用堆栈大小错误
- 未捕获的类型错误:this.reset不是函数-在ajax调用后清空输入时出错
- 从.ascx文件调用Javascript函数时出错
- 在NPObject上调用方法时出错:(一个理想的)PhoneGap项目
- "无法调用方法'打开'未定义的“;使用indexedDB.open时出错
- JQuery尝试进行Ajax调用时出错
- 在javascript中调用php时出错
- 在提交事件上调用 ajax 时出错
- 递归方法调用出错
- Backbone.js Collection'的fetch调用出错
- 使用UUID时Ajax调用出错