hi everyone..
i successfully passed some data from ajax to handler...but i cant able to pass the context(image request)..
here is my code in handler
please hit the breakpoint in handler and run it..the run flow is not going to upload function
public class Handler : IHttpHandler {
public void ProcessRequest(HttpContext context)
{
if (context.Request.QueryString["action"] == "upload")
{
string id = context.Request.QueryString["iden"].ToString();
if (id != null)
{
upload(id, context);
}
}
}
private void upload(string ProductID, HttpContext context)
{
if (context.Request.Files.Count == 1)
{
HttpPostedFile file = context.Request.Files[0];
file.SaveAs(context.Server.MapPath(".\\ProductImage\\ProductID\\") + file.FileName);
context.Response.Write("File uploaded");
}
}
public bool IsReusable {
get {
return false;
}
}
}
// here is my ajax code
$.ajax({
url: "new_prod.aspx/insert",
type: "post",
data:'{}',
dataType: "json",
success: function (response) {
alert(response.d);
var ident = response.d;
identi = ident;
$.ajax({
url: "Handler.ashx?action=upload&iden=" + identi,
type: "post",
allowedTypes: "png,gif,jpg,jpeg"
});
},
failure: function (response) {
alert("failure");
}
});
});
here is my c# code
[System.Web.Services.WebMethod]
public static long insert(string pcategory, string category, string scategory, string ssno, string sname, string scity, string pcode, string soption, string primage, string ititle, string ilocation, string pprice, string pweight, string avail, string pdes, string swoption)
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["conn"]);
SqlCommand cmd = new SqlCommand();
DataSet ds = new DataSet();
SqlDataAdapter adapt = new SqlDataAdapter();
con.Open();
cmd.CommandText = "insert into new_prod(parent_category,category,sub_category,supplier_style_no,supplier_name,supplier_city,product_code,size_option,prod_image,image_title,image_location,prod_price,prod_weight,availability,prod_description,switc_option) values ('" + pcategory + "','" + category + "','" + scategory + "','" + ssno + "','" + sname + "','" + scity + "','" + pcode + "','" + soption + "','" + primage + "','" + ititle + "','" + ilocation + "','" + pprice + "','" + pweight + "','" + avail + "','" + pdes + "','" + swoption + "')";
string join = cmd.CommandText + "select @@identity";
cmd = new SqlCommand(join, con);
long ReturnType_long = Convert.ToInt64(cmd.ExecuteScalar());
con.Close();
return ReturnType_long;
}