Javascript Question

Extjs 5.0.1 How to send a JSON POST request the proper way

Good day all. I'm totally new to Extjs and I've been inserted into a big project already started and left alone.
I'm studing the framework of course, but I'm getting struck every bit of code.

Now, I'd like to understand the proper way to make a rest call, using JSON parameters in POST.

this is my actual situation:

I have defined a combobox in the view file (called setup.js) and I've put a listener on select like the following

emptyText: 'Select a country',
listConfig: {
itemTpl: [
'<div><span class="" style="margin-right: 10px;"><img src="resources/flags/{id}.png"></span>{name}</div>'
listeners: {
/*created the after render listener to wait until the store is loaded. then I set the default value*/
select: 'onCountrySelect',
afterrender: 'onAfterRenderCombo'

on another file, called setupController.js I've defined all my functions:

onCountrySelect: function(a){
console.log("selected ",a.value);
var controller = this,
userData = controller.getUserData();

Now, on every country select action, I've to send a JSON to a server, to "set" the country used by the user. The call depends also on the enviroment as the dev one is different from the production one, so I guess that I have to make some sort of proxy, but maybe this is a later issue, now I'd like to setup a call for this selection, so I'll use this logic for all the future calls I have to do.

questions are, is there a proper way to define it? do I need a model? or is good to have al the calls in the store? do I need a... proxy(?) or a store or something "external" so I can use the very same call in some other places? is there an example for this?

Guys/Girls, thanks in advance.

Answer Source

Like written here

A proxy is made to work with a server on the same domain:

AjaxProxy cannot be used to retrieve data from other domains. If your application is running on it cannot load data from because browsers have a built-in security policy that prohibits domains talking to each other via AJAX.

Personally Having a console connecting with more than one server, I use an ajax request like that




I'm working on a personal proxy, extended by ajax proxy, to do the ajax call without different domain problems. If you want to do an home made proxy you can read all you want about proxy here:

or simply you can use an external JS class that do the ajax request for you.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download