If this is your first visit, check our documentation. To post, register or login.
Forums / Community Contributed Add-Ons / Contribution-Writing Guidelines / jQuery ajax with type POST and securityToken

jQuery ajax with type POST and securityToken

Started by pasi on 10 Dec 2012, 11:25 AM · Views: 7,720

Results 1 to 3 of 3
10 Dec 2012, 11:25 AM
#1
pasi avatar

pasi

Zen Follower

Join Date:
Mar 2004
Location:
Finland
Posts:
435
Plugin Contributions:
1

Post #1 by pasi

Just a little notice for anyone working with jQuery ajax in the admin side. (or probably any type of ajax for that matter that uses POST data instead of GET)

When using POST to transfer the query to your php script, you need to include the securityToken in the posted data, or else the response will contain the admin index page (with return code 302 for redirect).

This is of course only valid, if you include the "includes/application_top.php" in the php script.

Hope this helps someone else not to waste time on debugging :)

Working with Zen Cart since 2003 :: www.prr.fi
Author of the original Finnish language pack for Zen Cart since 2004

3 Feb 2013, 8:18 AM
#2
jegor avatar

jegor

New Zenner

Join Date:
Feb 2013
Location:
Verona, Italy
Posts:
1
Plugin Contributions:
0

Post #2 by jegor

Hi Pasi!
Thanks for the advice, I've passed many hours trying out to find the way.. and now it doesn't redirect to home!
BUT now it shows the "you cannot access to this resource".. how you managed to solve this problem?

Thank you!

Jegor

26 Mar 2013, 9:38 AM
#3
pasi avatar

pasi

Zen Follower

Join Date:
Mar 2004
Location:
Finland
Posts:
435
Plugin Contributions:
1

Post #3 by pasi

I haven't ran across the problem you mention, so can't help you there.

BUT

I did find another new fun AJAX feature....

Debugged this the whole morning..!

I installed zencart to my developement server and made an addon that uses ajax, which worked fine.

The code checks if the user is logged in before returning the JSON code.

Then I uploaded the shop to a live server and edited the config files. Shop is working and the AJAX script is working when I log in and access the ajax handler directly.

But when accessing the page that has the ajax call it didn't work and the session was terminated (a new session cookie was being set)

After 3 hours of debugging, I realized that the AJAX query was made to http://www.example.com//test/ajax.php

and the problem is, the browser doesn't send a cookie to http://www.example.com//test/ajax.php as the shops address is http://www.example.com/test/ajax.php

eg. it thinks the extra "/" in the URL makes it another domain.

Hope this helps others :)

Working with Zen Cart since 2003 :: www.prr.fi
Author of the original Finnish language pack for Zen Cart since 2004