PDA

View Full Version : ajax Post not working


Nivec
04-29-2013, 10:25 PM
Hi all,

I have a script that does the following:

$.ajax({
type: 'POST', url: './misc.php',
data: { 'do': 'cloc',
'action': 'updatevp',
'X': X,
'Y': Y}
})



Then in the Plugin, hook ?misc_start?, I have:

if($_REQUEST['do'] == 'cloc') {

switch($_REQUEST['action']) {
case ' updatevp':
$vbulletin->db->query_write("UPDATE MyCustomTable SET X = {$vbulletin->input->clean_gpc('r', 'X', TYPE_NUM)}, Y = {$vbulletin->input->clean_gpc('r', 'Y', TYPE_NUM WHERE fkiUserID = {$vbulletin->userinfo['userid']}");
break;
}
}



It works fine if do this:

$.ajax('./misc.php?do=cloc&action=updatevp&X=' + X + '&Y=' + Y)



Why can I not ?POST? it?

I am creating or at least trying to create my first pluging, so all this is a little new to me, am I missing something simple?

Thanks

Nivec
05-02-2013, 09:08 AM
Eventually found the problem, I had to pass the security token as well:

'securitytoken': SECURITYTOKEN


So the post now looks like:

$.ajax({
type: 'POST', url: './misc.php',
data: { 'do': 'cloc',
'action': 'updatevp',
'X': X,
'Y': Y,
'securitytoken': SECURITYTOKEN}
})

Zachery
05-02-2013, 12:40 PM
Good job finding the issue :)

Lynne
05-02-2013, 05:29 PM
... and thanks for posting the solution! :)

tbworld
05-02-2013, 09:10 PM
Good job and thumbs up for posting the answer. Really makes the thread useful to the the community.