The responseText property of XMLHttpRequest object is returning the whole HTML page
-
Hello all, I am a newbie to the AJAX programming techniques. I want to update my database as per choice made by the user and inform him/her about the same if the updation has been done successfully. The platform is ASP.NET Following is my implementation: The file containing following two javascript functions has been included in my ASPX file. This function (i.e. submitValue) is called on the button click and the parameter (i.e. value) is the data I want to update on my database. The function "getXmlHttp()" in bold is returning the required XMLHttpRequest object by using the suitable method as per the browser detected. As I want to inform the user on the same page so the variable "requestURL" passed in the open() function contains the URL of the same page with updated querystring. function submitValue(value) { try { //Create the XMLHttpRequest object. xmlHttp = getXmlHttp(); //Call the function to process the response from the server xmlHttp.onreadystatechange = stateChanged; //Send request to the server var requestURL = location.href+"&q="+value; xmlHttp.open('GET',requestURL,true); xmlHttp.send(null); } catch(e) { alert("Error : Sending request"); } } Following javascript function which is called above is used to process the server response. function stateChanged() { try { if (xmlHttp.readyState==4 ||xmlHttp.readyState=='complete') { var retValue; retValue = xmlHttp.responseText; if(retValue=="0") document.getElementById("divRateInfo").innerHTML = "Rating submition failed. Try again."; else document.getElementById("divRateInfo").innerHTML = "Rating successfully submited!"; } } catch(e) { alert("Error : Processing response"); } } Finally following is the code behind written on the corresponding ASPX.CS file. The method is called on the page load. private void SaveRating() { try { if (Request.QueryString["q"] != null) { int nUserRate = Convert.ToInt32(Request.QueryString["q"].ToString()); SqlParameter[] sqlParam = new SqlParameter[2]; sqlParam[0] = new SqlParameter("@rate", SqlDb
-
Hello all, I am a newbie to the AJAX programming techniques. I want to update my database as per choice made by the user and inform him/her about the same if the updation has been done successfully. The platform is ASP.NET Following is my implementation: The file containing following two javascript functions has been included in my ASPX file. This function (i.e. submitValue) is called on the button click and the parameter (i.e. value) is the data I want to update on my database. The function "getXmlHttp()" in bold is returning the required XMLHttpRequest object by using the suitable method as per the browser detected. As I want to inform the user on the same page so the variable "requestURL" passed in the open() function contains the URL of the same page with updated querystring. function submitValue(value) { try { //Create the XMLHttpRequest object. xmlHttp = getXmlHttp(); //Call the function to process the response from the server xmlHttp.onreadystatechange = stateChanged; //Send request to the server var requestURL = location.href+"&q="+value; xmlHttp.open('GET',requestURL,true); xmlHttp.send(null); } catch(e) { alert("Error : Sending request"); } } Following javascript function which is called above is used to process the server response. function stateChanged() { try { if (xmlHttp.readyState==4 ||xmlHttp.readyState=='complete') { var retValue; retValue = xmlHttp.responseText; if(retValue=="0") document.getElementById("divRateInfo").innerHTML = "Rating submition failed. Try again."; else document.getElementById("divRateInfo").innerHTML = "Rating successfully submited!"; } } catch(e) { alert("Error : Processing response"); } } Finally following is the code behind written on the corresponding ASPX.CS file. The method is called on the page load. private void SaveRating() { try { if (Request.QueryString["q"] != null) { int nUserRate = Convert.ToInt32(Request.QueryString["q"].ToString()); SqlParameter[] sqlParam = new SqlParameter[2]; sqlParam[0] = new SqlParameter("@rate", SqlDb
Hi dear, Ur code is perfect for xmlhttp, may be there is some bug in the page where u r getting response.. try debug the code by direct opening the url with passed parameters u now can easily trace the bug if any..
Hello Forum Always be in touch to help about the topic ASP.NET