Problem with sending data to server

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem with sending data to server

mmoore
When I run     http://localhost:18080/commission/dwr/test/jsTestIt  it works perfectly. So I know everything is set up okay.

The problem comes when I try to incorporate the scripts into my STRUTS/JSP page. 

I have literally copied the code from the testing page (.../dwr/test/jsTestIt)    into my jsp page

 getProgram(    <input class='itext' type='text' size='10' value='""' id='p00' title='Will be converted to: java.lang.String'/>  );
  <input class='ibutton' type='button' onclick='jsTestIt.getProgram(objectEval($("p00").value), reply0);' value='Execute'  title='Calls jsTestIt.getProgram(). View source for details.'/>
  <script type='text/javascript'>
    var reply0 = function(data)
    {
      if (data != null && typeof data == 'object') alert(dwr.util.toDescriptiveString(data, 2));
      else dwr.util.setValue('d0', dwr.util.toDescriptiveString(data, 1));
    }
  </script>
  <span id='d0' class='reply'></span>
AND
<script type='text/javascript'>
  function objectEval(text)
  {
    text = text.replace(/\n/g, ' ');
    text = text.replace(/\r/g, ' ');
    if (text.match(/^\s*\{.*\}\s*$/))
    {
      text = '[' + text + '][0]';
    } 
    return eval(text);
  }
  </script>


The problem is, showing to be in the line above in red. The Chrome debugging tool says:
"Uncaught TypeError Cannot read property 'replace' of undefined "

Obviously this code works on the TEST page. What is going on here?



Thanks
Mike


Reply | Threaded
Open this post in threaded view
|

Re: Problem with sending data to server

Mike Wilson
Administrator
The error message says that you are calling your function objectEval with its "text" parameter set to undefined. Put a breakpoint in the Chrome debugger to see where this is coming from.
 
This has nothing to do with DWR. I think you may need to read up on how JSP and JavaScript works as I can't really make sense of what you are doing here. Try to cut down your code until you get something that works and then take smaller steps.
 
Best regards
Mike Wilson
 
Michael Moore wrote:
When I run     http://localhost:18080/commission/dwr/test/jsTestIt  it works perfectly. So I know everything is set up okay.

The problem comes when I try to incorporate the scripts into my STRUTS/JSP page. 

I have literally copied the code from the testing page (.../dwr/test/jsTestIt)    into my jsp page

 getProgram(    <input class='itext' type='text' size='10' value='""' id='p00' title='Will be converted to: java.lang.String'/>  );
  <input class='ibutton' type='button' onclick='jsTestIt.getProgram(objectEval($("p00").value), reply0);' value='Execute'  title='Calls jsTestIt.getProgram(). View source for details.'/>
  <script type='text/javascript'>
    var reply0 = function(data)
    {
      if (data != null && typeof data == 'object') alert(dwr.util.toDescriptiveString(data, 2));
      else dwr.util.setValue('d0', dwr.util.toDescriptiveString(data, 1));
    }
  </script>
  <span id='d0' class='reply'></span>
AND
<script type='text/javascript'>
  function objectEval(text)
  {
    text = text.replace(/\n/g, ' ');
    text = text.replace(/\r/g, ' ');
    if (text.match(/^\s*\{.*\}\s*$/))
    {
      text = '[' + text + '][0]';
    } 
    return eval(text);
  }
  </script>


The problem is, showing to be in the line above in red. The Chrome debugging tool says:
"Uncaught TypeError Cannot read property 'replace' of undefined "

Obviously this code works on the TEST page. What is going on here?



Thanks
Mike


Reply | Threaded
Open this post in threaded view
|

Re: Problem with sending data to server

david@butterdev.com
In reply to this post by mmoore
Instead of copying code from the test page without understanding anything that is going on I recommend downloading the dwr.war and taking a look at some of the examples.  The test pages are automatically generated and not how you want to do things in your application.  That being said this error is being thrown because the 'text' argument is undefined.  My guess is you are not including the DWR util scripts and the value of the text input is not being sent to objectEval ($("p00").value).

On 03/31/2015 06:50 PM, Michael Moore wrote:
When I run     http://localhost:18080/commission/dwr/test/jsTestIt  it works perfectly. So I know everything is set up okay.

The problem comes when I try to incorporate the scripts into my STRUTS/JSP page. 

I have literally copied the code from the testing page (.../dwr/test/jsTestIt)    into my jsp page

 getProgram(    <input class='itext' type='text' size='10' value='""' id='p00' title='Will be converted to: java.lang.String'/>  );
  <input class='ibutton' type='button' onclick='jsTestIt.getProgram(objectEval($("p00").value), reply0);' value='Execute'  title='Calls jsTestIt.getProgram(). View source for details.'/>
  <script type='text/javascript'>
    var reply0 = function(data)
    {
      if (data != null && typeof data == 'object') alert(dwr.util.toDescriptiveString(data, 2));
      else dwr.util.setValue('d0', dwr.util.toDescriptiveString(data, 1));
    }
  </script>
  <span id='d0' class='reply'></span>
AND
<script type='text/javascript'>
  function objectEval(text)
  {
    text = text.replace(/\n/g, ' ');
    text = text.replace(/\r/g, ' ');
    if (text.match(/^\s*\{.*\}\s*$/))
    {
      text = '[' + text + '][0]';
    } 
    return eval(text);
  }
  </script>


The problem is, showing to be in the line above in red. The Chrome debugging tool says:
"Uncaught TypeError Cannot read property 'replace' of undefined "

Obviously this code works on the TEST page. What is going on here?



Thanks
Mike