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 2 of 2
  1. #1
    Regular Coder StealthRT's Avatar
    Join Date
    Aug 2006
    Posts
    185
    Thanks
    14
    Thanked 0 Times in 0 Posts

    Exclamation Sending data with xmlhttp

    Hey all i am in need of some help with the xmlhttp ajax stuff. I am using a script called "SEXYALERTBOX". I am using it to allow the user to input a password. The textbox is called BoxPromptInput. I do not think its inside a <form> tag.

    Here is the code:
    Code:
    function askForPass() {
      Sexy.prompt('Please type the password in order to see the pictures/videos','' ,{ onComplete: 
        function(returnvalue) {
          if(returnvalue)
          {
    		  
            var xmlhttp = false;
    		var pageResponse = null;
    		
    		try{xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");} 
    		catch (error){try {xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");} catch (error) {xmlhttp = false;}}
    		if (!xmlhttp && typeof XMLHttpRequest!='undefined') {try {xmlhttp = new XMLHttpRequest();} catch (error) {xmlhttp=false;}}
    		if (!xmlhttp && window.createRequest) {try {xmlhttp = window.createRequest();} catch (error) {xmlhttp=false;}}
    		
    		var parameters = "";
    		var url = "mediacheck.asp";
    		var formArray = returnvalue;
    		
    			for(i=0; i < formArray.length; i++) {parameters = parameters + formArray[i].name + "=" + encodeURIComponent(formArray[i].value) + "&";}
    			
    			xmlhttp.open("POST", url + '?' + Math.random(), true);
    			xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    			xmlhttp.setRequestHeader("Content-length", parameters.length);
    			xmlhttp.setRequestHeader("Connection", "close");
    			xmlhttp.send(parameters);
    			xmlhttp.onreadystatechange = function() {
    				if (xmlhttp.readyState == 4) {
    					if (xmlhttp.status == 200) {
    						alert('worked');
    					}
    					else {
    						alert('An error occurred: ' + xmlhttp.status + ' ' + parameters);
    					}
    				}
    			}
    		
    		
          }
          else
          {
            Sexy.error('Exited');
          }
        }
      });
    }
    How can i pass the value inside the BoxPromptInput box to my mediacheck.asp page?

    This is what my mediacheck.asp page looks like:
    Code:
    <%
    Dim myPass
    
    	myPass = request.form("BoxPromptInput")
    	
    	if myPass = "mypasstest" then
    		Session("mediasee") = "yes"
    		Session.Timeout = 30
    		response.write "WORKED!"
    	else
    		Session("mediasee") = "no"
    		response.write "NOTWORK"
    	end if
    %>
    Could anyone help me out finding a way to pass the value since im sure the request.form would not work in this case since its not in a form.

    Any help would be great! THANKS!

    David

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,121
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    Yes, it *IS* in a FORM. So far as the ASP code is concerned.

    That's what the lines here are doing:
    Code:
    	for(i=0; i < formArray.length; i++) {parameters = parameters + formArray[i].name + "=" + encodeURIComponent(formArray[i].value) + "&";}
    			
    	xmlhttp.send(parameters);
    The parameters are simulating the effect of a <FORM METHOD=POST>.

    So *if* your formArray includes that field it should work.

    But the formArray is coming from this code:
    Code:
    var formArray = returnvalue;
    and the returnValue is coming from the function call argument:
    Code:
    function(returnvalue) {
    But I don't pretend to know what the heck is setting the value of that argument, since you don't show your other code.


  •  

    Posting Permissions

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