Tag: jquery

JQuery ajax调用MVC操作总是在没有错误时返回错误

这是一个MVC3应用程序。 我有以下javascript调用我的操作: function editDescription(docId,fileName, fileDescription) { $.ajax({ type: “POST”, url: “/OrderDetail/LoadModelData”, contentType: “application/json; charset=utf-8”, data: “{‘id’: ‘”+docId +”‘, ‘filename’: ‘”+fileName+”‘, ‘description’: ‘”+fileDescription+”‘}”, dataType: “json”, success: function (result) { alert(“ok: “+ result.d); }, error: function (result) { alert(‘Oh no: ‘+ result.responseText); } }); inheritance人我的行动: [HttpPost] public string LoadModelData(string id, string filename, string description) { return filename; […]

添加toastr javascript asp.net webform

我试图在使用按钮提交表单后显示一个toastr消息(信息,错误等)并更新gridview控件(在asp.net webform中的更新面板中。感谢

将C#datetime解析为javascript datetime

我知道我的问题与其他人类似,但我没有找到解决问题的方法。 我有一个C#DateTime属性 public DateTime MyDate { get;set;} 当我使用ajax获取一些信息时,我在javascript中写道: $.each(object, function(k,v){ alert(object.MyDate); }); 它返回如下内容: /Date(1362478277517)/ 可以将日期时间转换为javascript日期吗? 谢谢。

使用jquery使用.net Web服务

我创建了这个从sql server db返回数据表的Web服务。 有人可以用jquery帮我显示它吗? 网络服务 [WebService(Namespace = “http://tempuri.org/”)] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [ScriptService] public class WebService : System.Web.Services.WebService { DataTable dt = new DataTable(); [WebMethod] public DataTable dbAccess() { using (SqlConnection conn = new SqlConnection( ConfigurationManager.ConnectionStrings[“localConnectionString”] .ConnectionString)) { using (SqlDataAdapter da = new SqlDataAdapter()) { conn.Open(); da.SelectCommand = new SqlCommand(“SELECT VehicleMake FROM VehicleMakes”, conn); da.Fill(dt); } […]

MVC和JQuery:检索表单数据的最佳实践

我有一些使用Ajax的JQuery将信息发送回我的控制器进行处理 我是这样做的: //Define my controls … …. …. //Get the values from my controls var param1= $(“#pName”).val(); …. …. //Define the return URL. Is this how to send info back? var url = ‘/?ID=’ + id + “&param1=” + param1 + “&param2=” + param2 + “&param3=” + param3 + “&param4=” + param4 + “&param5=” + […]

将带有撇号的json值发送到webservice时出现无效的对象错误

我试图将一个json对象发送到Web服务,以反序列化为自定义(LineItemWithDetails)对象。 当json中的任何地方都有apstrophes传递给webservice时,我得到以下错误。 在这种情况下,它是“BudgetJustification”。 我不知道我应该在这做什么。 $.ajax({ type: “POST”, url: baseUrl + “/WebService/BudgetGrid.asmx/SaveLineItemDetails”, data: “{details: ‘” + JSON.stringify(_lineItemObj) + “‘, categoryId: ” + _lineItemObj.LineItem.CategoryID + “, lineItemId: ” + _lineItemObj.LineItem.ID + ” }”, contentType: “application/json; charset=utf-8”, dataType: “json”, success: function (response) { }, error: function (response) { ShowError(response.responseText); } }); [WebMethod(true)] public string SaveLineItemDetails(string details, int categoryId, […]

asp.net mvc 4 javascript里面的razor block抛出错误

这是我的剃刀代码,它会抛出错误: @section script { $(document).ready(function () { @if (TempData[“Message”] != null) { showNotification(“‘” + TempData[“Message”].ToString() + “‘”); } }); } 它说showNotification不存在。 它认为这是一个C#代码,它是一个javascript函数。 有人可以告诉我如何解决这个错误? 谢谢!

完成ASP.NET页面加载后运行javascript函数

我需要在页面完成后从ASP.NET代码运行一个javascript函数。 到目前为止我已经使用过这段代码,但它返回“undefined”,因为当javascript函数被触发时,隐藏字段没有填充值。 我该怎么办? 提前完成。 ASPX: 使用Javascript: function HandleColors() { alert($(‘#’).val()); } 代码背后: ColorHiddenField.Value = item.Color; ScriptManager.RegisterClientScriptBlock(this, this.GetType(), “script”, “HandleColors();”, true);

有jQuery倒计时的问题? functionserverSync:serverTime

serverSync:serverTime函数从服务器返回值,但我检查了服务器和客户端时间都相同。当我调用服务器与服务器同步时,它不会显示倒计时。 帮我 ? $(function() { var shortly = new Date(); var newTime = new Date(‘April 9, 2010 20:38:10’); //for loop divid /// $(‘#defaultCountdown’).countdown({ until: shortly, onExpiry: liftOff, onTick: watchCountdown, serverSync: serverTime }); $(‘#div1’).countdown({ until: newTime }); }); function serverTime() { var time = null; $.ajax({ type: “POST”, //Page Name (in which the method should be […]

向客户端显示exception消息

在我的asp.net mvc应用程序中,我想向用户显示用于抛出exception的错误消息。 ajax请求中发生exception。 我试过这个: 在Global.asax.cs文件中,我有全局应用程序error handling程序: protected void Application_Error(object sender, EventArgs e) { Exception exception = System.Web.HttpContext.Current.Server.GetLastError(); // do something so that client side gets the value exception.Message // I have tried these, but no success HttpContext.Current.Response.StatusDescription = exception.Message; HttpContext.Current.Response.StatusCode = 1000; // custom status code } 在javascript中,我有全局的ajaxError处理程序: $(document).ajaxError(function (xhr, props) { // show the […]