Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Shells Virtual Desktop
BMail.ag - Secure Email Service
Server.net
CPLicense.net
VPS Server
Buy VPN
Vultr
VMs for AI
HostDare
ReliableSite White-Label Dedicated Hosting for Resellers
InterServer VPS
BMail.ag - Secure Email Service
Best VPN
High-Performance Bare Metal Server Solutions
Karvl.com
Server Mania Cloud Hosting
DataWagon Hosting
AlphaVPS Hosting
Evoxt.com
Clouvider
VPS Hosting with NVMe
Residential IPs in the US & 4G Mobile Proxies in EU & US with Unlimited Bandwidth
ReliableSite White-Label Dedicated Hosting for Resellers
Rabisu - Hosting Solutions
Shells Virtual Desktop
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

Jquery Help

fresher_06fresher_06 Member
edited November 2012 in Help

Hi all..

I just wanted to keep all of my jquery code externally which is currently inside my main .php file.
Facing one challenge as below --

In my php file I have this jquery code --

$userid = mysql_real_escape_string($_SESSION['uid']);

var userid = <?php echo "$userid"; ?>; //getting used in the Ajax call

Now but when I keep this code in an external .js file then how do I get the userid in javascript variable . which is actually coming from $_SESSION Variable ..

Any clue ??

Comments

  • @fresher_06 said: $userid = mysql_real_escape_string($_SESSION['uid']);

    var userid = <?php echo "$userid"; ?>; //getting used in the Ajax call

    This is not jquery code. You do not need javascript to pass the userid. The userid is stored in a SESSION variable and can be kept on the PHP side.

  • @Corey .. i am using it in this way ..

    $(document).ready(function() {
    var username = '<?php echo "$username"; ?>';
    var userid = '<?php echo "$userid"; ?>'; //getting used in the Ajax call
    });

    Then using the userid later as below in the ajax call

    var dataString = '&cust_id='+ userid +'&cust_final_points='+ cust_final_points_val;

    $.ajax({ type: "POST", url: "update_cust_results.php", data: dataString, : :
    .. more code .
  • @fresher_06 then just do this on the javascript side....

    $.ajax({ type: "POST", url: "update_cust_results.php" });

    Then on update_cust_results.php hold all of the user variables in the SESSION array.
    $_SESSION['username'];
    $_SESSION['userid'];
    $_SESSION['cust_final_points'];
    $_SESSION['cust_final_points_val'];

    Every time you call the PHP script those variables will still be in the SESSION array just like you left them, no need to pass them around to javascript.

Sign In or Register to comment.