Magento is prompting for admin login in response 302 after executing an AJAX call

I am facing an issue with my AJAX request in Magento block which triggers an action in my module controller. The problem is that the response of this request is a 302 status code, leading to a redirect to the admin sign-in page if I am not logged in. However, this request should be accessible from the front-end and does not require admin authentication.

Here is my JavaScript code:

var xmlhttp;
if(typeof XMLHttpRequest !== 'undefined') xmlhttp = new XMLHttpRequest();
xmlhttp.open("POST", "http://mac-4.local:8888/magento_sample_1.4.2/index.php/disponibilityshippingicon/disponibility/setcustomeraddressinsession/", true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send('city=' + jsonAddress['city'] + '&cp=' + jsonAddress['cp'] + '&country=' + jsonAddress['country']);

And here is my controller code:

class ColisWeb_DisponibilityShippingIcon_DisponibilityController extends Mage_Adminhtml_Controller_Action
{

public function setcustomeraddressinsessionAction() {
    $params = $this->getRequest()->getParams();
    Mage::log("ColisWeb - Visitor's address not pushed into session : " . $params['city'] . $params['cp'] . $params['country'], Zend_log::INFO);
    if (isset($params['city'], $params['cp'], $params['country'])) {

        //new Mage_Customer_Model_Address();
        $address =  Mage::getModel('customer/address');
        $address->setCity($params['city']);
        $address->setPostCode($params['cp']);

        $session = Mage::getSingleton('core/session');
        $session->setData('addressColisweb', $address);
        $session->setData('cityAddressColisweb', $params['city']);
        $session->setData('postCodeAddressColisweb', $params['cp']);
        $session->setData('contryAddressColisweb', $params['country']);


    }
    else {


    }


    $this->getResponse()->setHeader('Content-type', 'application/json', true) ;
    $result = array( 'status' => '200');
    $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));   
}

}
?>

This pertains to my version of Magento 1.4.2

Your assistance on this matter would be greatly appreciated.

Thank you for your help!

Answer №1

The Mage_Adminhtml_Controller_Action you are currently using should be replaced with

Mage_Core_Controller_Front_Action
.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Hide the form field upon button click

I currently have a form with 6 input fields all under the same id entry1. Whenever I click the Add Section button, these fields are cloned and added to the form. There is also a button for removing the section above. The issue arises when I click on the R ...

Expanding AngularJS capabilities with multiple ng-repeat directives in a single row of a table

This question is related to displaying a collection of Grandchildren in AngularJS. The current for loop structure is as follows: foreach(var parent in list) foreach (var child in parent) foreach (var grandChild in child) print(grandChild.item1) ...

What are the benefits and drawbacks of combining Jquery UI with AngularJS in web development?

Currently, I am developing a Web application and considering integrating JqueryUI and AngularJS into my ASP.NET MVC project. Is this the best decision for my project? Are there any recommended Databinding libraries that can be used with JQuery UI? Please ...

Master the art of string slicing in JavaScript with these simple steps

I am attempting to utilize the slice function to remove the first three characters of a string within a JSON object. $(document).ready(function() { $.ajaxSetup({ cache: false }); setInterval(function() { $.getJSON("IOCounter.html", functio ...

Opposite path matching with Next.js middleware

For my Next.js project, I have implemented a middleware and now I need it to only apply to routes that do not start with /api/. I have checked the documentation but couldn't find a similar example. Is there a way to achieve this without manually excl ...

What is the best way to hide a custom contextmenu in AngularJs?

I created a custom contextmenu directive using AngularJs. However, I am facing an issue where the menu is supposed to close when I click anywhere on the page except for the custom menu itself. Although I have added a click function to the document to achie ...

Error message: The 'event' variable is not defined in the Firebase function

I am in the process of creating an appointment application which includes a notification feature. I have integrated Firebase functions to send notifications to users when a new appointment is booked or canceled. However, I encountered an error that says Re ...

Securing RESTful APIs with stringent security measures

Lately, I've been delving into using modern front end technologies such as React and Angular. This has led me to explore tools like JSON Server for simulating restful database interactions. I've noticed that most REST APIs require authentication ...

What is the most effective way to retrieve the full height of a webpage using JavaScript

  Is there a way to get the actual height of the webpage, not just the browser screen height? I noticed that clientHeight only returns the height of the window! Thank you for your help! ...

Transforming functions with dependencies into asynchronous operations with the help of promises

Can I convert both of my functions into asynchronous functions, even though one function relies on the other? Is it feasible for function b to execute only after function a? ...

Side-menu elevates slider

Struggling to keep my slider fixed when the side-menu slides in from the left? I've scoured for solutions without luck. Any expert out there willing to lend a hand? Code Snippet: https://jsfiddle.net/nekgunru/2/ ...

What are some strategies for speeding up CRUD operations in a Django app that uses Ajax and Json? Is the sluggishness related to handling 7000 records, and if so, what steps can be taken

I am currently working with a remote legacy MySQL database that contains around 7000 records. The Update / Delete / Create operations are taking approximately 1.5 minutes to complete. I have imported the necessary files which are not included in Views.py b ...

Tips for incorporating external JavaScript code into React components

I have been tasked with integrating a graphical widget into a React component for a project I am working on. The widget_api code provided by RIPE Stat is required to accomplish this. Previously, in HTML5, the integration was successful using the following ...

The jQuery code written is not accurately delivering the expected value upon clicking

I have a dynamic list of items retrieved from the database. This list is generated using a while loop in PHP and echoed to the page. However, I am facing an issue where jQuery only recognizes the first item even if I click on a different one. My goal is to ...

Leveraging the Railway Pathway from the Google Maps API

I need to customize my map to display only railway stations instead of the entire map. How can I achieve this? Below is the code I have attempted: <html> <head> <style type="text/css"> html { height: 100% } ...

What is the proper way to request confirmation before making updates or deletions to data?

my current situation is as follows: I am utilizing an el-table component to display data fetched from an API. I have organized this data into a computed property so that I can easily sort, filter, and paginate the table. Additionally, I have incorporated ...

Showcasing certain elements as the user scrolls

Looking for a way to display an element (such as a div) when the user scrolls without using JQuery? Here's an example that tries to achieve this: var scroll = document.body.scrollTop; var divLis = document.querySelectorAll("div"); for(let i = 0; i ...

Guide to passing the parent state as a prop to a child component and enabling the child to modify the state

I have a situation where my parent component holds 4 buttons to set a payment state, and I need to pass this state to a text field child component. Additionally, I want the text field to be editable so that the state can also be modified through it. My att ...

Implementing a strategy to prevent the browser's back button from functioning

Is there a way to prevent the user from using the back button in a single page application? I've tried methods like onhashchange and window.history.forward, but they don't seem to be effective (perhaps because the URL doesn't change). ...

I am experiencing an issue where my AngularJS CORS request is not reaching the server

Recently, I encountered a problem with my Spring MVC API backend where CORS was correctly configured. However, when attempting to make an Ajax call, Chrome threw the following error: XMLHttpRequest cannot load 172.20.16.45:8082/cuponza. The request was ...