In my VIew, i have added a button and when i click on it, the Controller class gets called. The value’s in the View (textfield values) , will be sent over the URL from the web service. Then the server will return a JSON string shown below;
{“value”:”SUCCESS”}
Now, i need to sent this JSON string back to the view, and the view will alert the user depending on the JSON response. If the JSON returned SUCCESS, then a Success alert will get displayed and if the JSON returned FAIL, then a Fail alert will be displayed.
1.) In my code, i can only display the JSON response from the VIEW, but how can i send it to the COntroller ? (var text = response.responseText; displays the JSON response)
2.) How could i, separate the string from the view, and only get the SUCCESS or FAIL string from the JSON response ?
Button Implementation, From the View Class
xtype:'button',
id:'when_button_click',
text:'Send',
ui:'confirm',
The COntroller CLass
Ext.define(‘myapp.controller.testcont’, {
extend: "Ext.app.Controller",
config: {
refs: {
newNoteBtn: "#when_button_click"
},
control: {
newNoteBtn: {
tap: "onNewNote"
}
}
},
onNewNote: function () {
var values = Ext.getCmp('form').getValues();
console.log("inside onNewNote function");
Ext.Ajax.request({
url: 'http://call.com/the_webservice',
params : values,
failure: function (response) {
var text = response.responseText;
console.log("fail");
}, success: function (response) {
var text = response.responseText;
console.log("success");
}
});
}
// init and launch functions omitted.
});
Why you want to pass the values back to the
viewfrom thecontroller?I don’t see any valid reason to do so.
You can show the
Ext.Msg.alertin the controller itself onsuccessandfailureof Web Service like this,EDIT:
Do something like this ..