X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   Using ajax calls in template - 403 Forbidden Error (https://forum.x-cart.com/showthread.php?t=74801)

acidon 12-18-2016 04:36 AM

Using ajax calls in template - 403 Forbidden Error
 
I am trying to use Ajax to pass some data to php file from template.

In template in javascript:


Code:


$(document).ready(function() {
$(".redeem-button").click(function(){
            var test = 'test';
            $.ajax({
                url: 'modules/Custom/ajaxtest.php',
                data: {test: test},
                type: 'POST',
                success: function (data) {
                    $(".apply-left").html(data);
                }
            });
        });
});


When I test it, I get this error in console:

Code:

POST http://localhost/xcart/modules/Custom/ajaxtest.php 403 (Forbidden)

I tried to add:

Code:

require_once 'http://localhost/xcart/auth.php';

in ajaxtest.php but still no luck...

How do I make it work?

totaltec 12-18-2016 02:05 PM

Re: Using ajax calls in template - 403 Forbidden Error
 
Usually, you don't call the modules directory directly in a script. Try placing your ajaxtest.php in the root directory.

cherie 12-18-2016 04:47 PM

Re: Using ajax calls in template - 403 Forbidden Error
 
This error is probably because /modules/.htaccess has "deny from all". Don't circumvent this security but call a php file outside of this directory.

Off the top of my head you may want to start with one of the Block examples like:
  1. skin/common_files/modules/Customer_Reviews/ajax.rating.js (calls loadBlock for rating_bar)
  2. skin/common_files/js/ajax.js (loadBlock calls get_block.php)
  3. get_block.php
  4. modules/Customer_Reviews/func.php (func_ajax_block_rating_bar())

acidon 12-22-2016 04:27 AM

Re: Using ajax calls in template - 403 Forbidden Error
 
Quote:

Originally Posted by totaltec
Usually, you don't call the modules directory directly in a script. Try placing your ajaxtest.php in the root directory.


Moving ajaxtest.php to root solved the problem! Thanks a lot, sir!

Quote:

Originally Posted by cherie
This error is probably because /modules/.htaccess has "deny from all". Don't circumvent this security but call a php file outside of this directory.

Off the top of my head you may want to start with one of the Block examples like:
skin/common_files/modules/Customer_Reviews/ajax.rating.js (calls loadBlock for rating_bar)
skin/common_files/js/ajax.js (loadBlock calls get_block.php)
get_block.php
modules/Customer_Reviews/func.php (func_ajax_block_rating_bar())


Thanks for these references, already found some good bits there!


All times are GMT -8. The time now is 07:03 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.