• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 197
  • Last Modified:

JAVASCRIPT - send data vis querystring...however dont need the actual window to open...

here is my code..yet I dont need the window to open..would window.XMLREQUEST be a better option to use..?

<script type="text/javascript">
<!--

function SEND_DATA_onclick() {

    var message = document.getElementById("<%=TextBox1.ClientID%>").value;
    var ph_number = document.getElementById("<%=TextBox2.ClientID%>").value;  
 
    // YOU MUST SEND YOUR CREDENTIALS EVERYTIME TO USE THE ....
    // IF YOUR CREDENTIALS ARE NOT AUTHENTICATED...YOUR REQUEST WILL NOT WORK...
    // YOU CAN HARDCODE IT HERE:
    var USERNAME = '1s2f3h'
    var PASSWORD = '9o6g5d'
   
 
  if (message != '' & ph_number != '') {
          window.load ("2.aspx?USERNAME='" + USERNAME + "'&PASSWORD='" + PASSWORD +
          "'&c_msg1='" + message + "'&p_num1='" + ph_number + "'")
  }
}


-->
</script>
0
GlobaLevel
Asked:
GlobaLevel
  • 2
1 Solution
 
bartvdCommented:
You can use this function:

function openPage(pageurl){
var ajaxObject;
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  ajaxObject=new XMLHttpRequest();
  }
else if (window.ActiveXObject)
  {
  // code for IE6, IE5
  ajaxObject=new ActiveXObject("Microsoft.XMLHTTP");
  }
else
  {
  alert("Your browser does not support Ajax!");
  }

ajaxObject.onreadystatechange=function(){
if(ajaxObject.readyState==4)
  {
  var data=ajaxObject.responseText;
  }
}

ajaxObject.open("GET",pageurl,true);
ajaxObject.send(null);

}
0
 
haloexpertsexchangeCommented:
using ajax/jquery you can do something like this.
$('clickedelement').click(function(){
  var message = document.getElementById("<%=TextBox1.ClientID%>").value;
    var ph_number = document.getElementById("<%=TextBox2.ClientID%>").value;  

  var USERNAME = '1s2f3h'
    var PASSWORD = '9o6g5d'
   
$.get('2.aspx',{'USERNAME':USERNAME, 'PASSWORD':PASSWORD, 'c_msg1':message, 'p_num1':ph_number}, function(data){
    });

Open in new window

data is what is returned from the ajax call to be inserted into the current page if necessary.
replaced clickedelement with how ever you want to distinguish the element to be clicked that fires this off.
0
 
GlobaLevelAuthor Commented:
So how would this work...is this the right idea?


<script type="text/javascript">
<!--

function SEND_DATA_onclick() {

    var message = document.getElementById("<%=TextBox1.ClientID%>").value;
    var ph_number = document.getElementById("<%=TextBox2.ClientID%>").value;  
 
    // YOU MUST SEND YOUR CREDENTIALS EVERYTIME TO USE THE ....
    // IF YOUR CREDENTIALS ARE NOT AUTHENTICATED...YOUR REQUEST WILL NOT WORK...
    // YOU CAN HARDCODE IT HERE:
    var USERNAME = '1s2f3h'
    var PASSWORD = '9o6g5d'
    
 
 // if (message != '' & ph_number != '') {
 //         window.load ("2.aspx?USERNAME='" + USERNAME + "'&PASSWORD='" + PASSWORD + 
 //         "'&c_msg1='" + message + "'&p_num1='" + ph_number + "'")
 // }
 
 var pageurl = "2.aspx?USERNAME='" + USERNAME + "'&PASSWORD='" + PASSWORD + 
          "'&c_msg1='" + message + "'&p_num1='" + ph_number + "'"
          
 // CALL THE FUNCTION....         
 openPage(pageurl)
          
 }
 
 function openPage(pageurl){
var ajaxObject;
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  ajaxObject=new XMLHttpRequest();
  }
else if (window.ActiveXObject)
  {
  // code for IE6, IE5
  ajaxObject=new ActiveXObject("Microsoft.XMLHTTP");
  }
else
  {
  alert("Your browser does not support Ajax!");
  }

ajaxObject.onreadystatechange=function(){
if(ajaxObject.readyState==4)
  {
  var data=ajaxObject.responseText;
  }
}

ajaxObject.open("GET",pageurl,true);
ajaxObject.send(null);

} 



-->
</script>

Open in new window

0
 
bartvdCommented:
Yes exactly. If you want the data that is on the page, it is stored in the var data. You can use it there.

If you only need to send data, this should work.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now