jQuery.post() get global var from others php files

43 Views Asked by At

I have a problem. I am using forum (SMF) I am creating some script in jQuery whose job is to read information from something, processing the information and resending and replacing the tags in the forum post.

I do this because it takes time to process and the page would take longer to load.
My problem is that I have variables whose origin I don't know and some are attached to a class so they give callbacks or be function.

My question is if anyone knows what and how to be able to use variables that are already loaded by loading the forum but in the jquery.post request I don't have them anymore.

    global $txt, $modSettings, $scripturl, $user_info,$smcFunc;

    loadLanguage('xx');

or..

        if (allowedTo('view_attachments') || $modSettings['magnet_guest'])
        {
            $request = $smcFunc['db_query']('', '
                SELECT
                    a.id_attach, a.id_msg, a.fileext, a.downloads
                FROM {db_prefix}attachments AS a
                WHERE a.id_msg = {int:message_id}
                    AND a.fileext = {string:torrent_ext}
                ORDER BY a.downloads',
                array(
                    'message_id' => $cache_msg_id,
                    'torrent_ext' => 'torrent',
                )
            );
            $(function() {
                $('strong button#magnet_hook').each(function() {
                    const $temp_id_load = $(this).data('temp_id');
                    
                    $.post("update.php",
                    {
                        magnet: $('a#magnet_hook[data-temp_id="'+$temp_id_load+'"]').attr('href'),
                        msg_id: $('a#magnet_hook[data-temp_id="'+$temp_id_load+'"]').data('msg_id'),
                        temp_id: $('a#magnet_hook[data-temp_id="'+$temp_id_load+'"]').data('temp_id')
                    },
                    function(data, status){
                        const $tracker_data_split = data.split("    ");
                        $('a#magnet_hook[data-temp_id="'+$tracker_data_split[0]+'"]').html($tracker_data_split[1]);
                    });
                });
            });
            
            $("strong button#magnet_hook").click(function() {
                const $temp_id = $(this).data('temp_id');

                $('a#magnet_hook[data-temp_id="'+$temp_id+'"]').html('Updating trackers!');

                $.post("update.php",
                {
                    magnet: $('a#magnet_hook[data-temp_id="'+$temp_id+'"]').attr('href'),
                    msg_id: $('a#magnet_hook[data-temp_id="'+$temp_id+'"]').data('msg_id'),
                    temp_id: $('a#magnet_hook[data-temp_id="'+$temp_id+'"]').data('temp_id')
                },
                function(data, status){
                    const $tracker_data_split = data.split("    ");
                    $('a#magnet_hook[data-temp_id="'+$tracker_data_split[0]+'"]').html($tracker_data_split[1]);
                });

            });

I try say on smf forum question, AND read 50% internet in google :P

0

There are 0 best solutions below