Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: jQuery ASHX
Hello all, I'm used this code to pass parameter from jQuery to 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');
    }
and this ASHX code:
<%@ WebHandler Language="C#" Class="Handler2" %>
 
using System;
using System.Web;
using System.IO;
using System.Web.Services;
using System.Web.Script.Services;
using System.Web.Script.Serialization;
public class Handler2 : IHttpHandler, System.Web.SessionState.IRequiresSessionState
{
    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;
        }
    }
}
Posted 20-Feb-13 22:04pm
Edited 20-Feb-13 22:05pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 7,105
1 DamithSL 5,079
2 Maciej Los 4,866
3 Sergey Alexandrovich Kryukov 4,617
4 Kornfeld Eliyahu Peter 4,384


Advertise | Privacy | Mobile
Web01 | 2.8.141223.1 | Last Updated 21 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100