Quantcast
Channel: Web Forms
Viewing all articles
Browse latest Browse all 23244

call handler from javascript asp.net .aspx page

$
0
0

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
 

<div class="productPriceWrapRight">

<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 

<div class="pre-action-link" id="premain0" width="100%"> 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[&quot;Aaction&quot;] != null)
        {
            string action = HttpContext.Current.Request.Form[&quot;action&quot;].Trim();
            int pRODUCTid = Convert.ToInt32(HttpContext.Current.Request.Form[&quot;productID&quot;]);
            if (action.Equals(&quot;addToBasket&quot;))
            {
                ShoppingCart.Instance.AddItem(pRODUCTid);
            }   

        }
 
    } 

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
 
    public void AddToCart()
    { 
        //Code for inserting Item into Cart
    }
    public void DeleteFromCart()
    { 
    }

Viewing all articles
Browse latest Browse all 23244

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>