Reputation: 143
I am trying to process the json response, returned from the server side.For that I have set Callback function which will be executed on successful response from the server side,and process the server response further by accepting it as parameter, but its not working.
This is my html code:
<form id="EditorsForm">
UserName:<br>
<input type="text" name="uname" id="uname">
<br> Password:
<br>
<input type="password" name="password" id="password">
<br><br>
<input type="button" value="Submit" onclick="google.script.run.withSuccessHandler(onSuccess).verifyUser(this.form)">
</form>
This is my Callback function
function onSuccess(response) {
alert(response);
}
This is my app script which returns successful json response.
function verifyUser(EditorsForm) {
var uname = EditorsForm.uname;
var password = EditorsForm.password;
login_api = "http://api.abcbrain.in/operations/login.php?userName=" + uname + "&password=" + password + "&referrer=ePlugin";
var resp = UrlFetchApp.fetch(login_api);
var json = resp.getContentText();
var data = JSON.parse(json);
return data;
}
Upvotes: 1
Views: 153
Reputation: 143
I have just tested your code with hardcoded JSON in verifyUser() function as follows,
function verifyUser(EditorsForm){
var uname=EditorsForm.uname;
var password=EditorsForm.password;
/*login_api="http://api.smsbrain.in/operations/login.php?userName="+uname+"&password="+convertSign(password)+"&referrer=excelPlugin";
"http://api.smsbrain.in/1.2/appsms/brandStatus.php?user="+uname+"& passwd="+password+"&senderId="+sid+"";
var resp=UrlFetchApp.fetch(login_api); */
var json = '{"resp1":"test"}';//resp.getContentText();
var data = JSON.parse(json);
Logger.log(data)
return data;
}
and it is giving me proper result
I think the problem is with UrlFetchApp it must be throwing an exception. can you just use "try catch block" to make sure it's not throwing any exception.
Upvotes: 1