I have developed a front-end JavaScript page that collects user data and stores it in a variable. My web application functions like a Facebook-type platform, but it is actually a decision support system based on fuzzy logic.
My question is, will my JavaScript page be shared by all users or will a new page be created for each user who requests a page utilizing that JS script?
This is important to me because I need to store some data globally within the JS page, which is accessed by different JS functions on the same page. If a single JS page is shared among all users, concurrency may impact the values in that global variable.
JavaScript Code:
var Data_obj = new Object(); // Global variable
$(document).ready(function () {
docReady();
});
function docReady() {
// Preventing # links from scrolling to the top
$('a[href="#"][data-top!=true]').click(function (e) {
e.preventDefault();
});
// Chosen - enhances select options
$('[data-rel="chosen"],[rel="chosen"]').chosen();
// Tabs functionality
$('#myTab a:first').tab('show');
$('#myTab a').click(function (e) {
e.preventDefault();
$(this).tab('show');
});
// Handling events for specific elements within the table
$('#applicant_table tbody').on("click",".cv_info",function (e) {
e.preventDefault();
Cv_path=$(this ).attr("cv_path");
$("#cv_data").html('<object data="'+Cv_path +'" type="application/pdf" width="450" height="460"></object>');
$('#myModal_cv').modal('show');
});
$('#applicant_table tbody').on("click",".msg",function (e) {
e.preventDefault();
Data_obj.E_mail=$(this ).attr("email");//Data fetch and stored in object
Data_obj.name=$(this ).attr("name");
$('#myModal_email').modal('show');
});
$('#applicant_table tbody').on("click",".setting",function (e) {
e.preventDefault();
Data_obj.can_id=$(this ).attr("can_id");
alert(can_id);
//$('#myModal_setting').modal('show');
});
}
// Event listener for filter option change
$( "#filter_option" ).change(function() {
$("#applicant_table tbody").empty();
$( "#filter_option option:selected" ).each(function()
{
var van_id=$("#Job_title option:selected").val();
var Duration=$(this).val();
if(van_id!="")
{
var Obj=new Object();
Obj.duration=Duration;
Obj.van_id=van_id;
$.ajax({
type: "POST",
url: '/Arsenal/requritment/Update_Application_table',
contentType: 'application/json',
data: JSON.stringify(Obj),
success: function(Data){
for(var i=0;i<Data.length;i++)
{
data=Data[i];
if(data.can_id!=null)
{
var a='<tr><td><b>'+data.apply_date+'</b></td><td><b><i>'+data.name+'</i></b></td><td><b>'+data.phone+'</b></td><td><span class="label-success label label-default">New</span></td><td> <i class="glyphicon glyphicon-list-alt cv_info" cv_path="/Arsenal/requritment/getCv?can_id='+data.can_id+'"></i> <i class="glyphicon glyphicon-envelope msg" email="'+data.e_mail+'" name="'+data.name+'" ></i> <i class="glyphicon glyphicon-cog setting" email="'+data.e_mail+'" can_id="'+data.can_id +'"></i></td></tr>';
$("#applicant_table tbody").append(a);
}
}
}
});
}
});
});
function Send_Message()
{
alert(Data_obj.name); // Retrieving data
Msg_title=("#title_name").val();
Msg_body=("#content_info").val();
$('#myModal_email').modal('hide');
}