0

I am trying to run an ajax call with jqGrid. However, the parameters are not being sent to the getRequest() all of the time.

If I do the javascript:

var param1 = document.getElementById("idInput").value;
var url = "${ctx}/Method.action?getTheseRecords&param1="+param1;

Then when I call in the Java it comes back blank. However, I if set the var param1, then I get the right data.

So this works:

var param1 = "M";
var url = "${ctx}/Method.action?getTheseRecords&param1="+param1;

So the first way gives an empty String, and the second gives a String == "M":

String param1 = getRequest().getParameter("param1");

I don't know if somebody knows why this isn't working? Because I have looked at the url before putting it into the Ajax, and it is fine.

Zendie
  • 1,176
  • 1
  • 13
  • 30
Chula
  • 1
  • 1
  • 1
    Check if the `idInput` field name matches correctly and it has value. That will answer. – Sunil Dabburi Dec 11 '19 at 23:03
  • I have a feeling this will answer your question ~ [Why does jQuery or a DOM method such as getElementById not find the element?](https://stackoverflow.com/questions/14028959/why-does-jquery-or-a-dom-method-such-as-getelementbyid-not-find-the-element) – Phil Dec 11 '19 at 23:23
  • I have had that problem a lot with jQuery as well. Thanks Phil! This problem turned out to be an error for how I was calling every search after the initial with reload. – Chula Dec 16 '19 at 16:18

1 Answers1

0

You do not encode your url. That might be the problem.

var url = "${ctx}/Method.action?getTheseRecords&param1=" + encodeURIComponent(param1);

Other than that, everything seems fine to me.

Halil Bahar
  • 31
  • 1
  • 1
  • Good advice in general but I can pretty much guarantee this won't solve the problem. – Phil Dec 11 '19 at 23:24
  • I did do something like that. I found out what the problem was. The jqGrid was reloading with the original url. So I needed to change the url during the reload. This was just a rookie mistake on my part. Thank you – Chula Dec 16 '19 at 16:16