cant store returned values from ajaxJSON function

Use this board to ask questions or have discussions with other Rich Displays users.
Post Reply
Paul_Ramcharitar
Profound User
Posts: 91
Joined: Fri Aug 03, 2012 11:07 am
First Name: Paul
Last Name: Ramcharitar
Company Name: Banks DIH
City: Georgetown
Zip / Postal Code: 592
Country: Guyana
Contact:

cant store returned values from ajaxJSON function

Post by Paul_Ramcharitar »

Hi this is my ajaxJSON function:

Code: Select all

ajaxJSON({ 
	  url: "/php/sig_image_store.php",
	  params: {
		sig: bmpString,
		name: imageName
	  },
	  method: "post",
	  async: true,
	  handler: infoHandler
	});
This if my infoHandler function:

Code: Select all

function infoHandler(obj) {
    alert("Result: " + obj.data);
    if(obj.data != 'success'){
		changeElementValue("sigSaveId",'N');
	}else{
		changeElementValue("sigSaveId",'Y');
	}
	alert(get('sigSaveId'));	
}
I'm trying to assign a text field with id "sigSaveId" with the value "Y" or "N"

The ajax request is successful. it sends back obj.data with "success". But when i try to assign obj.data or any variable within the infoHandler function, nothing gets assigned.

Help please.
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: cant store returned values from ajaxJSON function

Post by Scott Klement »

What type of widget is "sigSaveId"?
Paul_Ramcharitar
Profound User
Posts: 91
Joined: Fri Aug 03, 2012 11:07 am
First Name: Paul
Last Name: Ramcharitar
Company Name: Banks DIH
City: Georgetown
Zip / Postal Code: 592
Country: Guyana
Contact:

Re: cant store returned values from ajaxJSON function

Post by Paul_Ramcharitar »

Its a hidden Textbox widget. I know for some reason, "changeElementValue" doesn't work on dynamic output fields, but they work on input fields like textboxes.
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: cant store returned values from ajaxJSON function

Post by Scott Klement »

I coded up your example, almost exactly as you posted it, and did not have any trouble, it worked perfectly for me.

Here's the RPG I used:

Code: Select all

     H DFTACTGRP(*NO)

     FTESTD     CF   E             WORKSTN EXTFILE('SKTEST/TESTD')
     F                                     HANDLER('PROFOUNDUI(HANDLER)')

     C                   exfmt     testd1
     C     sigSaveId     dsply
     c                   eval      *inlr = *on 
Here's the display file I used:

Code: Select all

     A                                      INDARA
     A          R TESTD1
     A                                  1  2HTML('QPUIREC0    ')
     A                                  1  3HTML('{"screen":{"record format nam-
     A                                      e":"testd1"},"items":[{"id":"Button-
     A                                      1","field type":"button","css class-
     A                                      ":"button","value":"Call Ajax Func"-
     A                                      ,"left":"112px","top":"82px","width-
     A                                      ":"115px","cursor":"default","oncli-
     A                                      ck":"ScottKlement.paulAjax();"},{"i-
     A                                      d":"sigSaveId","field type":"textbo-
     A                                      x","css class":"input","value":{"fi-
     A                                      eldName":"SigSaveId","dataLength":"-
     A                                      10","trimLeading":"false","trimTrai-
     A                                      ling":"true","blankFill":"false","r-
     A                                      jZeroFill":"false","dataType":"char-
     A                                      ","formatting":"Text","textTransfor-
     A                                      m":"none","designValue":"[SigSaveId-
     A                                      ]"},"left":"68px","top":"137px","vi-
     A                                      sibility":"hidden"},{"id":"Button2"-
     A                                      ,"field type":"button","css class":-
     A                                      "button","value":"Return to RPG","l-
     A                                      eft":"191px","top":"194px","width":-
     A                                      "108px","cursor":"default","respons-
     A                                      e":{"fieldName":"btnRtnRpg","dataTy-
     A                                      pe":"indicator","formatting":"Indic-
     A                                      ator","indFormat":"1 / 0"}}]}')
     A            BTNRTNRPG      1A  H
     A            SIGSAVEID     10A  H 
And he'res the JavaScript I used to make it work

Code: Select all

var ScottKlement = { }

ScottKlement.paulAjax = function() {

  ajaxJSON({
     url: "/ScottTemp/paulJson.txt",
     params: {
      sig: "sig here",
      name: "image name here"
     },
     method: "post",
     async: true,
     handler: ScottKlement.infoHandler
   });

} 

ScottKlement.infoHandler = function(obj) {
  alert("result; " + obj.data);
  if (obj.data != 'success') {
	changeElementValue("sigSaveId", 'N'); 
  } else {
	changeElementValue("sigSaveId", 'Y'); 
  }
  alert(get('sigSaveId'));
}
This worked perfectly for me
Paul_Ramcharitar
Profound User
Posts: 91
Joined: Fri Aug 03, 2012 11:07 am
First Name: Paul
Last Name: Ramcharitar
Company Name: Banks DIH
City: Georgetown
Zip / Postal Code: 592
Country: Guyana
Contact:

Re: cant store returned values from ajaxJSON function

Post by Paul_Ramcharitar »

Hi Scott, the way how you did the javascript with the structure, worked for me as well. I'm not sure why, lol

Thanks a lot for your help.
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests