The error is:
ReferenceError: $portal is not defined $portal.user = {
i am writing whole new thing with Jquery and normal javascript.(this is my first web project still learning.)
I am trying to execute $portal.user.init() function from Jquery document ready function, it is not executing.
I may be missing something, could any one please help, how i should call above method from Jquery & concept behind it.
here is my jQuery code
<script type="text/javascript">
$( document ).ready(function() {
// Initiate portal..
$portal.user.init(<?php echo $_SESSION['user_id']; ?>,
"<?php echo $_SESSION['user_name']; ?>",
"<?php echo $_SESSION['acc_type']; ?>",
"<?php echo $_SESSION['lang']; ?>",
"<?php echo $_SESSION['first_name']; ?>",
"<?php echo $_SESSION['last_name']; ?>",
"<?php echo $_SESSION['picture']; ?>",
"<?php echo $_SESSION['email']; ?>"
);
});
And i created another javascript file say myweb.js code is like this
var _no_profile_pic = "../img/no_profile_pic.png";
/*
* Class : $portal.user
* Desc : Portal User Related Functions
*/
$portal.user = {
user_id: 0,
user_name: '',
acc_type: '',
lang: '',
first_name: '',
last_name: '',
picture: '',
email: '',
/*
* $portal.user.init : Initilise user
* Params :
* user_id - user id
* user_name - login user name
* acc_type - Type of user account like (A - Admin, V - Verified, U - Unverified, D - Deleted)
* lang - User Language like (en-english)
* first_name - User First Name
* last_name - User Last Name
* picture - User Picture URL
* email - User Email Address
* Returns : None
*/
init: function(user_id, user_name, acc_type, lang, first_name, last_name, picture, email)
{
$portal.user.user_id = user_id;
$portal.user.user_name = user_name;
$portal.user.acc_type = acc_type;
$portal.user.lang = lang;
$portal.user.first_name = first_name;
$portal.user.last_name = last_name;
$portal.user.picture = (picture == indef || picture == '' ? _no_profile_pic : picture);
$portal.user.email = email;
alert(this.user_id);
}
};
indef? ->picture == indef- For undefined or empty you can.picture = picture || _no_profile_pic,(That glob is probably better put within the class as well)