Hello All,
please help.
unable to call the handler file.
I building a shopping cart in which the add to cart button is build like this
<img width="111" height="32" id="featuredProduct_1" alt="Add To Basket" src="images/add-to-basket2.gif">
</div>
which call a handler (.ashx file) from a javascript on top of the page like dis
Collapse | Copy
Code</div><script type="text/javascript">var httpReq = null;
function callASHX(id) {
alert(id);
httpReq = XMLHttpRequest();
httpReq.onreadystatechange = XMLHttpRequestCompleted;
httpReq.open("POST", "Handler.ashx?action=addToBasket&productID="+
document.getElementById(id).value, true);
httpReq.send(null);
} // initialize XMLHttpRequest object function XMLHttpRequest() {var xmlHttp;try {// Opera 8.0+, Firefox, Safari xmlHttp = new XMLHttpRequest();
}catch (e) {// IEBrowsers try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}catch (e) {try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}catch (e) {returnfalse;
}
}
}return xmlHttp;
}
function XMLHttpRequestCompleted() {if (httpReq.readyState == 4) {try {
alert(httpReq.responseText);
}catch (e) {
}
}
}</script>
which call ahandler file like this
public class Handler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
if (HttpContext.Current.Request.QueryString["Aaction"] != null)
{
string action = HttpContext.Current.Request.Form["action"].Trim();
int pRODUCTid = Convert.ToInt32(HttpContext.Current.Request.Form["productID"]);
if (action.Equals("addToBasket"))
{
ShoppingCart.Instance.AddItem(pRODUCTid);
}
}
}
public bool IsReusable
{
get
{
return false;
}
}
public void AddToCart()
{
//Code for inserting Item into Cart
}
public void DeleteFromCart()
{
}