Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

Using ajax calls in template - 403 Forbidden Error

 
Closed Thread
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #1  
Old 12-18-2016, 04:36 AM
  acidon's Avatar 
acidon acidon is offline
 

Senior Member
  
Join Date: Feb 2008
Posts: 139
 

Default 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?
__________________
Version 4.7.6 X-cart Gold
  #2  
Old 12-18-2016, 02:05 PM
  totaltec's Avatar 
totaltec totaltec is offline
 

X-Guru
  
Join Date: Jan 2007
Location: Louisville, KY USA
Posts: 5,823
 

Default 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.
__________________
Mike White - Now Accepting new clients and projects! Work with the best, get a US based development team for just $125 an hour. Call 1-502-773-6454, email mike at babymonkeystudios.com, or skype b8bym0nkey

XcartGuru
X-cart Tutorials | X-cart 5 Tutorials

Check out the responsive template for X-cart.

The following 2 users thank totaltec for this useful post:
acidon (12-22-2016), qualiteam (12-19-2016)
  #3  
Old 12-18-2016, 04:47 PM
  cherie's Avatar 
cherie cherie is offline
 

X-Wizard
  
Join Date: May 2003
Location: USA
Posts: 1,534
 

Default 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())
__________________
redlimeweb.com
custom mods and design integration
4.7 linux

The following 2 users thank cherie for this useful post:
acidon (12-22-2016), qualiteam (12-19-2016)
  #4  
Old 12-22-2016, 04:27 AM
  acidon's Avatar 
acidon acidon is offline
 

Senior Member
  
Join Date: Feb 2008
Posts: 139
 

Default 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!
__________________
Version 4.7.6 X-cart Gold

The following user thanks acidon for this useful post:
totaltec (12-23-2016)
Closed Thread
   X-Cart forums > X-Cart 4 > Dev Questions


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 06:31 PM.

   

 
X-Cart forums © 2001-2020