PDA

View Full Version : Adding the sessionhash to javascript/ajax


BBR-APBT
01-03-2010, 07:21 AM
I am having trouble adding the session hash to my javascript.

I suck at javascript so I really don't know where to start.

Here is my javascript from YUI

CODE REMOVED


Here is my code that calls the above

CODE REMOVED

The code in the ajax file is a simple SQL query.
I would like to convert this to the vb format if anyone would like to be nice.

This code works outside vbulletin so I can only guess it is because I am not sending the session hash.

winstone
01-03-2010, 11:04 AM
following line in your code sends the request to the PHP script, if you want to send the sessionurl, security token etc along with the rest of the data, you can simply add following 'already-defined' variables

url = "ajax/saveCopyright.php?photoId=" + escape(phId)+ "&text=" + escape(cr_text)+"&rand="+new Date().getTime();

javascript variables of SESSIONURL and SECURITYTOKEN are defined on every VB page, so you can modify the coed like this

url = "ajax/saveCopyright.php?photoId=" + escape(phId)+ "&text=" + escape(cr_text)+"&rand="+new Date().getTime() + "&sessionUrl=" + SESSIONURL + "&securityToken=" +SECURITYTOKEN;

edit, btw sessionhash is stored in the cookie, you can get that in your PHP script using a code like bellow

if(!empty($_COOKIE['bbsessionhash'])) {
$sessionHash = $_COOKIE['bbsessionhash'];
}

BBR-APBT
01-04-2010, 04:45 AM
Thanks man this didn't happen to be my problem.

I had a error in my sql syntax and sadly AJAX doesn't tell you unless you tell it too.