Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Apr 2007
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Ajax Inside a loop issue.

    I have a bit of a problem. I am trying to use ajax inside of an asp loop but it will not work in IE. It works fine in firefox tho.

    Here is the bit of code i am having trouble with.


    Ajax
    Code:
    <script type="text/javascript">
    
    function xmlhttpPost(strURL,formname,responsediv,responsemsg) {
    
        var xmlHttpReq = false;
    
        var self = this;
    
        // Xhr per Mozilla/Safari/Ie7
    
        if (window.XMLHttpRequest) {
    
            self.xmlHttpReq = new XMLHttpRequest();
    
        }
    
        // per tutte le altre versioni di IE
    
        else if (window.ActiveXObject) {
    
            self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    
        }
    
        self.xmlHttpReq.open('POST', strURL, true);
    
        self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    
        self.xmlHttpReq.onreadystatechange = function() {
    
            if (self.xmlHttpReq.readyState == 4) {
    
    			// Quando pronta, visualizzo la risposta del form
    
                updatepage(self.xmlHttpReq.responseText,responsediv);
    
            }
    
    		else{
    
    			// In attesa della risposta del form visualizzo il msg di attesa
    
    			updatepage(responsemsg,responsediv);
    
    
    
    		}
    
        }
    
        self.xmlHttpReq.send(getquerystring(formname));
    
    }
    
    
    
    function getquerystring(formname) {
    
        var form = document.forms[formname];
    
    	var qstr = "";
    
    
    
        function GetElemValue(name, value) {
    
            qstr += (qstr.length > 0 ? "&" : "")
    
                + escape(name).replace(/\+/g, "%2B") + "="
    
                + escape(value ? value : "").replace(/\+/g, "%2B");
    
    			//+ escape(value ? value : "").replace(/\n/g, "%0D");
    
        }
    
    	
    
    	var elemArray = form.elements;
    
        for (var i = 0; i < elemArray.length; i++) {
    
            var element = elemArray[i];
    
            var elemType = element.type.toUpperCase();
    
            var elemName = element.name;
    
            if (elemName) {
    
                if (elemType == "TEXT"
    
                        || elemType == "TEXTAREA"
    
                        || elemType == "PASSWORD"
    
    					|| elemType == "BUTTON"
    
    					|| elemType == "RESET"
    
    					|| elemType == "SUBMIT"
    
    					|| elemType == "FILE"
    
    					|| elemType == "IMAGE"
    
                        || elemType == "HIDDEN")
    
                    GetElemValue(elemName, element.value);
    
                else if (elemType == "CHECKBOX" && element.checked)
    
                    GetElemValue(elemName, 
    
                        element.value ? element.value : "On");
    
                else if (elemType == "RADIO" && element.checked)
    
                    GetElemValue(elemName, element.value);
    
                else if (elemType.indexOf("SELECT") != -1)
    
                    for (var j = 0; j < element.options.length; j++) {
    
                        var option = element.options[j];
    
                        if (option.selected)
    
                            GetElemValue(elemName,
    
                                option.value ? option.value : option.text);
    
                    }
    
            }
    
        }
    
        return qstr;
    
    }
    
    function updatepage(str,responsediv){
    
        document.getElementById(responsediv).innerHTML = str;
    
    }
    </script>

    Code:
     <input type="image" alt="Load Tests" name="Test<%=testload%>" id="buttons" height="18" src="../images/Plus-icon.png" width="17" onclick="xmlhttpPost('test.asp', <%=testload%>, 'MyResult', '<img src=\'pleasewait.gif\'>'); return false;" value="Save">
     <form name="<%=testload%>">
     <input type="hidden" value="<%=rs.Fields(iLoopVar)%>" name="course_id">
     <input type="hidden" value="<%=rss("course_abbr")%>" name="course_abbr">
     <input type="hidden" value="<%=s_id%>" name="student_id">
     </form>
    I am using asp to get the <%=testload%> from a database. It works fine with Firefox but IE will not run the code. I think the problem is in the onclick event where i am trying to plug in the dynamic form name. Is there a proper way do do this that I am missing. Thanks for the help.

  • #2
    New to the CF scene
    Join Date
    Apr 2007
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Tried to switch it to
    Code:
    <form name="<%=testload%>">
     <input type="image" alt="Load Tests" name="Test<%=testload%>" id="buttons" height="18" src="../images/Plus-icon.png" width="17" onclick="xmlhttpPost('test.asp', THIS.FORM, 'MyResult', '<img src=\'pleasewait.gif\'>'); return false;" value="Save">
     
     <input type="hidden" value="<%=rs.Fields(iLoopVar)%>" name="course_id">
     <input type="hidden" value="<%=rss("course_abbr")%>" name="course_abbr">
     <input type="hidden" value="<%=s_id%>" name="student_id">
     </form>
    But ie is still giving me an error at the same point.
    Last edited by Sabastion; 01-30-2012 at 04:07 AM.

  • #3
    New to the CF scene
    Join Date
    Apr 2007
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    here is the error
    Code:
    Webpage error details
    
    User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)
    Timestamp: Mon, 30 Jan 2012 04:09:15 UTC
    
    
    Message: Unknown runtime error
    Line: 162
    Char: 5
    Code: 0
    URI: student_detail.asp?s_id=91617
    Thats this section of the code.

    Code:
    function updatepage(str,responsediv){
    
        document.getElementById(responsediv).innerHTML = str;
    
    }

  • #4
    New to the CF scene
    Join Date
    Apr 2007
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    No Joke i just found the problem. The page the ajax is calling is a table with the information pulled from a database about the specific test.

    apparently even though it loads into a page you have to put the

    <html>
    <body>
    </body>
    </html>

    around the text. Apparently FF and others that is not needed. Something to keep in mind I guess.
    Last edited by Sabastion; 01-31-2012 at 02:08 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •