Как передать строковое значение из JavaScript в функцию в ASHX

Я использовал этот код для передачи параметра из jQuery в ASHX, на самом деле я хочу загрузить файл с помощью плагина Uploadify и отправить параметр с именем 'Id' в ASHX

function CallHandler() {
    $.ajax({
        url: "PIU.ashx/MyMethod",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        data: { 'Id': '10000' },
        responseType: "json",
        success: OnComplete,
        error: OnFail
    });
    return false;
}

function OnComplete(result) {
    alert(result);
}
function OnFail(result) {
    alert('Request Failed');
}

и этот код ASHX:

public void ProcessRequest(HttpContext context)
{
    var employee = Convert.ToInt32(context.Request["Id"]);

    JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
    string serEmployee = javaScriptSerializer.Serialize(employee);
    context.Response.ContentType = "text/html/plain";
    context.Response.Write(serEmployee);

    parent MyParent = (parent)context.Session["mahdZNUparent"];

    //the file data is the file that posted by Uploadify plugin
    HttpPostedFile PostedFile = context.Request.Files["Filedata"];

    string FileName = PostedFile.FileName; // whene i comment this line, the code works
    // properly, but when uncomment this line, the code get to 'Request Failed'
}

public bool IsReusable
{
    get
    {
        return false;
    }
}

Как я могу решить эту проблему!!!!!!!

1 ответ

Решение

Вы можете получить награбленное по этому адресу: http://encosia.com/using-jquery-to-consume-aspnet-json-web-services/

И этот тоже: Использование jQuery для AJAX с ASP.NET Webforms

Другие вопросы по тегам