Hello,
i am currently need to create a js function to do some calculation.
So i am creating an ajax call to a custom Entrypoint which will have to retrieve UserPrefs decimal digits and 1000s separator.
So which is the best way to do in php entrypoints? I’ve starting with:
Unfortunately too early to smile!
The Entrypoint is correct however the js function still get me undefined because of deferred ajax call .
The js function where the js file is added like an include in editviewdefs:
$(document).ready(function() {
var test = getUserInfo();
alert(test.tSeparator); //which should return "."
});
Then the getUserInfo():
function getUserInfo() {
$.ajax({
type: "POST",
url: 'index.php?entryPoint=getUserInfo', // Custom EntryPoint
//url: 'index.php?module=CDZ_Contracts_Mobile&action=getUserInfo', // Action in Custom Controller
dataType: "json",
success: function(data) {
var yourDataStr = JSON.stringify(data)
var obj = JSON.parse(yourDataStr);
// Run the code here that needs
// to access the data returned
alert(obj.tSeparator);
return obj;
},
error: function() {
alert('Error occured');
}
});
}
The alert in getUserInfo works as expected while alert(test.tSeparator); will return undefined.
In console i can see:
jQuery.Deferred exception: test is undefined
Any help is appreciate.
And what is the main difference between make an ajax call to a custom action in controller or to a custom Entrypoints?
inside getUserInfo function works as expected but if i call call the funciton from outside like here:
var test = getUserInfo();
and then i try to print the result like this:
alert(test.tSeparator);
It return Undefined probably because the value is returned before waiting async ajax to complete.
What do you think about?
Am i in a right way?
What needs to be changed?