vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   ajax Post not working (https://vborg.vbsupport.ru/showthread.php?t=297697)

Nivec 04-29-2013 10:25 PM

ajax Post not working
 
Hi all,

I have a script that does the following:
Code:

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


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

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:
Code:

$.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:
Code:

'securitytoken': SECURITYTOKEN
So the post now looks like:
Code:

$.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.


All times are GMT. The time now is 11:22 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01051 seconds
  • Memory Usage 1,715KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (5)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete