0
我想從jquery.ajax調用調用c#通用處理程序。jquery到asp.net c#通用處理程序
我的網站結構是: A /處理器/ dowork.ashx calling.aspx
這裏是上述文件的代碼: calling.aspx文件 <%@頁面語言= 「C#」 AutoEventWireup = 「真正的」 代碼隱藏= 「calling.aspx.cs」 繼承= 「myapp.calling」 %>
//the jsonDataObj looks like: 1,t
function sendData(jsonDataObj) {
var status = "";
jQuery.ajax({
type: "POST",
url: '/a/handlers/dowork.ashx/doit',
data: jsonDataObj,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (output, status, xhr) {
status = xhr.responseText;
statusCode = xhr.status;
console.log(status + " " + statusCode);
},
error: function (xhr, textStatus, errorThrown) {
status = "{'d':'0," + errorThrown + "'}";
status = status.replace(/'/g, '"');
statusCode = xhr.status;
console.log(status + " " + statusCode);
}
});
}
dowork.ashx.cs - 通用處理器
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Script.Serialization;
using System.Text;
using System.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using Elmah;
namespace myapp
{
public class dowork : System.Web.UI.Page, IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
}
public bool IsReusable
{
get { return false; }
}
[System.Web.Services.WebMethod()]
public static string doit(object data)
{
string status = string.Empty;
string number = string.Empty;
string letter = string.Empty;
dynamic strings = ((IEnumerable)data).Cast<object>().Select(x => x == null ? x : x.ToString()).ToArray();
number = strings(0).ToString();
letter = strings(1).ToString();
status = number + letter;
return status;
}
}
}
我的錯誤是:
Server Error in '/' Application.
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: Could not create type 'myapp.a.handlers.dowork'.
Source Error:
Line 1: <%@ WebHandler Language="C#" CodeBehind="dowork.ashx.cs" Class="myapp.a.handlers.dowork" %>
Source File: /a/handlers/dowork.ashx Line: 1
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.1038.0
我似乎無法弄清楚這一個。有什麼建議麼?
我這樣做:<%@ WebHandler LANGUAGE = 「C#」 代碼隱藏= 「dowork.ashx.cs」 類= 「myapp.dowork」 %>和它的更好,但現在我得到奇怪的錯誤:在System.Core.dll中發生類型'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException'的異常,但未在用戶代碼 – wl2m
@ will2m中處理我認爲'動態字符串'導致問題。可以將其更改爲實際數據類型。順便說一下,這是一個完全不同的問題。你可以在另一個帖子 – shu
@ will2m中得到這個東西嗎? – shu