If I have in main.js's file, global variable a = 5;
and I'm sending this variable with AJAX to PHP, is it possible to change this variable from the console or somehow from the outside and have AJAX send wrong parameter?
Here is an example:
var init = {
id: null,
setId: function(i){
this.id = i;
alert(this.id);
},
callAjax: function(){
alert(this.id);
}
};
If I have this, is it still possible to change?
If I have in main.js's file, global variable a = 5;
and I'm sending this variable with AJAX to PHP, is it possible to change this variable from the console or somehow from the outside and have AJAX send wrong parameter?
Here is an example:
var init = {
id: null,
setId: function(i){
this.id = i;
alert(this.id);
},
callAjax: function(){
alert(this.id);
}
};
If I have this, is it still possible to change?
Share Improve this question edited Oct 12, 2014 at 19:36 rink.attendant.6 46.4k64 gold badges110 silver badges157 bronze badges asked Oct 12, 2014 at 18:45 PiraTaPiraTa 4852 gold badges8 silver badges22 bronze badges3 Answers
Reset to default 1If it is accessible from console (since you are stating that its a global variable), it is possible to modify it from console, just by writing a=1
or anything.
If this variable is global than it is possible.
To prevent it you must use closures
Yes, you can open the browser's console (For Chrome: Ctrl+ Shift + I on PC, Command + Shift + I on Mac) and switch to the 'Console' tab. Then just edit the global variable by setting a=<whatever you want>
.
Because it is in the global scope, you will be able to change it before the AJAX request.