ajax Communication Programming¶
In intra-mart Accel Kaiden!, a function that makes ajax communication easy is provided.Basic ajax communication method is described here.
ajax Communication Basic¶
It shows simple ajax communication coding.
ServerCreate Action class, and return [jp.co.slcs.kaiden2.base.foundation.model.dto.LogicResultDto] which is converted to JSON.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 import jp.co.slcs.kaiden2.base.foundation.model.dto.LogicResultDto; import jp.co.slcs.kaiden2.base.foundation.util.ResponseWriter; import jp.co.slcs.kaiden2.base.foundation.conf.LogicResultStatus; import net.arnx.jsonic.JSON; @Execute(validator = false) public String index() { /**~omitted~**/ LogicResultDto result = new LogicResultDto(); result.data = "returning data to the client"; result.status = LogicResultStatus.SUCCESS.getName(); //success status result.message = "Process is successed"; ResponseWriter.writeJSon(JSON.encode(result)); return null; }
- Client
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 var ajax = KAIDEN.Ajax(); //call ajax library var criteria = {}; //value to be sent to the server //ajax execution (POST communication) ajax.postAuto("/*URL*/" , criteria , function(returnData) { //process at normal time } , function(returnData) { //process at error time } , function(returnData) { //process at warning time } );When ajax communication ends,
- Message is automatically displayed accordint to the LogicResultDto.status contents. *only when message is set
- In case of “success”, it displays success message by using imuiShowSuccessMessage()
- In case of “fail”, it displays error message by using imuiShowErrorMessage()
- In case of “warn”, it displays warning message by using imuiShowWarningMessage()
Each method is called according to the LogicResultDto.status contents.At this point, the value which was set in LogicResultDto.data is passed to the argument.Notes
It can be executed only by ajax.postAuto(“/*URL*/”); if the process when normal time/error time/warning time of ajax.postAuto() is unnecessary and if the value does not have to be sent to the server.Notes
When you do GET communication, the same process can be performed in ajax.getAuto().
Synchronous Communication¶
Following methods are used when you do synchronous communication.
- postSyncAuto();
- getSyncAuto();
Detail Control of ajax Communication¶
Following methods are effective when you control message display or other behaviours in detail.
- post();
- get();
Both methods return $.ajax(), so the programmer can control in detailed.