Results 1 to 3 of 3
  1. #1

    Default Encapsulated Plugin AJAX Call Fails with 400 Bad Request in ZC 2.1

    Hello,

    I'm developing an encapsulated plugin for Zen Cart 2.1 and have run into a persistent AJAX routing issue.

    My plugin successfully injects JavaScript onto the page, and that script makes a standard POST request to ajax.php with an action and method (e.g., ajax.php?act=MyAction&method=myMethod). The POST data correctly includes the securityToken.

    When the call is made, the server responds with a 400 Bad Request. This indicates the ajax.php router is receiving the request but rejects the action as invalid.

    My AJAX handler class (e.g., class zcAjaxMyAction) and its corresponding file (zcAjaxMyAction.php) are located in my plugin's .../catalog/includes/classes/ajax/ directory. The class and file names appear to follow the standard zcAjaxPascalCase convention.

    What is the definitive method for an encapsulated plugin to register its AJAX handler classes so they are discoverable by the ajax.php router? The automatic discovery does not seem to be working, and my attempts to manually register the path using an auto_loaders config file have failed.

    Any insight into the correct process for ZC 2.1 would be greatly appreciated. Thank you!
    Case Badges by Techiant

  2. #2
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    13,434
    Plugin Contributions
    94

    Default Re: Encapsulated Plugin AJAX Call Fails with 400 Bad Request in ZC 2.1

    It'll help if you could post the contents of your javascript/jquery and ajax class for review. If you're hesitant to post directly, send them to me via PM.

  3. #3

    Default Re: Encapsulated Plugin AJAX Call Fails with 400 Bad Request in ZC 2.1

    Quote Originally Posted by lat9 View Post
    It'll help if you could post the contents of your javascript/jquery and ajax class for review. If you're hesitant to post directly, send them to me via PM.
    Oh gosh! After smashing my head against this for several hours, I decided to just extensively test ajax.php and log every step. It turns out the issue was that I was setting my method as my_method which in ajax.php was failing at line 51:
    PHP Code:
    if (!isset($_GET['act'], $_GET['method']) || !preg_match('/^[a-zA-Z0-9]+$/'$_GET['act']) || !preg_match('/^[a-zA-Z0-9]+$/'$_GET['method'])) 
    I feel super dumb for not paying attention to that regex for $_GET['method'] but relieved that finally made the connection :)
    Case Badges by Techiant

 

 

Similar Threads

  1. 400 Bad Request
    By Coffinwear in forum PayPal Express Checkout support
    Replies: 3
    Last Post: 29 Nov 2010, 06:42 AM
  2. 400 Bad Request when downloading
    By groovyclipart in forum Setting Up Categories, Products, Attributes
    Replies: 0
    Last Post: 29 Oct 2010, 03:43 PM
  3. Bad Request (400) on Add to Cart in Safari/Chrome
    By cave.dox in forum General Questions
    Replies: 2
    Last Post: 9 Feb 2010, 03:22 PM
  4. Checkout Issue - HTTP 400 Bad Request
    By DPM in forum Templates, Stylesheets, Page Layout
    Replies: 5
    Last Post: 10 Feb 2009, 03:43 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR