0

Hi

I am not been able to receive URL parameters passed from my ajax code in my jsp.

Here is the code

function showDetails()
  {
	  document.detailsForm.sltdUser.value = selectedUserID;
	  alert('selectedUserID' + selectedUserID);


	  var httpRequest;
	  var url  = 'showDetails.jsp?sltdUser = ' + selectedUserID;

      if (window.XMLHttpRequest) { // Mozilla, Safari, ...
          httpRequest = new XMLHttpRequest();
          
      } 
      else if (window.ActiveXObject) { // IE
          try {
              httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
          } 
          catch (e) {
              try {
                  httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
              } 
              catch (e) {}
          }
      }

      if (!httpRequest) {
          alert('Giving up :( Cannot create an XMLHTTP instance');
          return false;
      }
     
      httpRequest.open('GET',url, true);
      httpRequest.onreadystatechange = function() { processResponse(httpRequest); };
      httpRequest.send(null);
	  
  }

  function processResponse(httpRequest) {

      if (httpRequest.readyState == 4) {
          if (httpRequest.status == 200) {
              alert(httpRequest.responseText);
          } else {
              alert('There was a problem with the request.');
          }
      }

  }

showDetails.jsp

<%
     String userId = request.getParameter("sltdUser");
   %>
   
   <script type="text/javascript">
     alert('userId' + userId);
   </script>

The problem is in the alert I see that userId is not taking the value passed.

Kindly help.

Thanks

Abhik

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by Thirusha
0

One cant use client side code to get the server side code, if u try printing out the userId it should be there. what u can do is assign the userId to a hidden field then alert the value of the hidden field.

0

I have already solved this and u CAN send client side code to server side. The parameter needs to be appended to the URL twice.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.