Angular's $http method is sending a GET request instead of a POST request

$http.post(main+'/api/getcard/', $.param({number: $scope.searchcard}), {headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'} })
        .then(function (response) {
            if(response.data != 0)
            {
                $location.path('/redeem/'+response.data.id);
                console.log(response.data);
            }
        });

Upon running the above code, my Chrome browser returns the following:

Request URL:http://cards.mporeda.pl/branch/api/getcard
Request Method:GET
Status Code:405 Method Not Allowed

However, when I run the same code on Laravel serve localhost:8000, I receive:

Request URL:http://localhost:8000/branch/api/getcard/
Request Method:POST
Status Code:200 OK

I have not made any additional $http configurations other than adding the header option in the request. There are no errors displayed in the console before this request, leading me to believe that the code is correct. Could there be an issue with my server or something else causing this discrepancy?

Answer №1

You have encountered a discrepancy between the URL specified in your code and the URL actually being used for the request.

The URL defined in your code is:
main+'/api/getcard/'

However, the URL currently being used for the request is:

Request URL:http://cards.mporeda.pl/branch/api/getcard

This inconsistency may be due to several reasons:

  1. Making a POST request when intending to make a GET request
  2. The server responding with a redirect status (301 or 302) that removes the trailing slash from the URL
  3. The browser automatically following the redirect and changing the request method to GET

If you review your list of requests, you should find the initial POST request.

To address this issue, it is recommended to examine the server-side code responsible for generating the redirect.

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

Trigger an AJAX request by clicking a button using PHP

I've seen this question asked multiple times, but none of the answers seem to relate to my specific situation. I have a button that when clicked, should call a JavaScript function, passing it a PHP variable. The AJAX will then send that variable to a ...

Angular route unable to detect Passport User Session

The navigation bar in the header features buttons for Register, Login, and Become a Seller. Upon user login, it displays logout and view profile buttons. This functionality is operational on all routes except one, causing a client-side error. user not def ...

What is the best way to create a new object in a Vue component with optimal efficiency?

Currently, I am working on initializing a map that would be utilized in my calculatePrice function. calculatePrice(key) { let prices = new Map({ 0: 17, 1: 19, 2: 24, 3: 27, 4: 30, 5: 46, 6: 50 ...

There seems to be a compatibility issue between AngularJS and HTML

Here is a simple AngularJS code snippet I have written: var app=angular.module("myApp",[]); app.controller("MyController",['$scope',function($scope){ $scope.name="Asim"; $scope.f1=function(){ console.log("i am clicked"); $scope.vr="lol"; } co ...

Is it possible for data transmitted or received through a socket written in various languages to be comprehended by both parties involved?

Is it possible for data to be transmitted accurately between two programs written in different languages (C++ and JavaScript using Node.js in this case) when connected through a socket? ...

Formatting code within an HTML document

I am attempting to customize a stock widget that I obtained from financialcontent.com. My current approach involves using Bootstrap for styling purposes. To incorporate the widget into a div, I found it necessary to embed the script directly within the HT ...

The display of ngtable is not appearing correctly

I recently downloaded the zip file of this plunkr (http://plnkr.co/edit/ISa4xg?p=preview) onto my computer. Upon running the example, I noticed that while the table displays correctly, the CSS styling is not applied properly (e.g. pagination appears in an ...

What steps can I take to resolve the CLIENT_MISSING_INTENTS issue?

After diving into learning about discord.js, I've run into a bit of a roadblock. Despite trying to troubleshoot by searching online, I can't seem to resolve the issue. const Discord = require('discord.js'); // const Discord = require(&a ...

Continual running of a jquery command

Here is a snippet of jQuery code that may need some clarification. In this code, when the element with ID 'box1' is clicked, it triggers an event that directs to a modal dialog where there is a class called 'colors'. The issue here is t ...

Resolving Laravel validation for a field linked to a relationship

I am facing an issue with validation in my blade template involving a dropdown select on a related table. Despite searching for a solution, I have been unable to find one. To temporarily resolve the issue, I decided to comment out the 'business_unit_ ...

How can we stop the brief display of a hidden div from occurring?

I have two divs on my webpage - one to display if JavaScript is disabled, and another if JavaScript is enabled. The issue I am facing is that even when JavaScript is not disabled, the div containing the message stating that JavaScript is disabled briefly ...

Is it time to release the BufferGeometry?

My scene objects are structured around a single root Object3D, with data loaded as a tree of Object3Ds branching from this root. Meshes are attached to the leaf Object3Ds using BufferGeometry/MeshPhongMaterial. To clear the existing tree structure, I use t ...

What is the best way to symbolize a breadcrumb offspring?

In my table representation, the breadcrumb is shown as: <ol class="breadcrumb" data-sly-use.breadcrumb="myModel.js"> <output data-sly-unwrap data-sly-list="${breadcrumb}"> <li itemscope itemtype="http://data-vocabulary.org/ ...

I encountered a console issue that I am struggling with. It is showing the error message "TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'"

When running this code, I encountered an error in the console (TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'). Can someone help me identify where I made a mistake and provide guidance ...

If the checkbox is selected, the textbox will receive the class "form-input validate required" upon Jquery validation

I am using Jquery Validation plugin to validate a form on my website. Below is the HTML form code: <form id="caller"> <label>Phone:</label> <input type="text" name="phone" id="phonen" class="form-input" value="" /> <di ...

I am sometimes experiencing issues with activating ajax code using Bootstrap 3 modal

I'm stumped trying to find a solution for this issue. Currently, I am utilizing the bootstrap modal to retrieve ajax content from a specified URL. To prevent content overlap, I am using $.removeData() when reloading the content. The problem arises w ...

Adjust the width of your table content to perfectly fit within the designated width by utilizing the CSS property "table width:

Example of a table <table> <tr> <td>Name</td> <td>John</td> <td>Age</td> <td>25</td> <td>Job Title</td> <td>Software Engineer ...

Reducing the length of Javascript code

Recently, I have been working on a project where I needed to use a piece of Javascript code to insert text into an input element when its label is double-clicked. $(document).ready(function() { $('#name-label').dblclick(function(){ $ ...

React component performing AJAX requests

I have a React component that utilizes highcharts-react to display a chart fetched from an API using some of its state properties. export default class CandlestickChart extends React.Component { constructor (props) { super(props); this ...

Hold on for the processing of a CSV document

I am attempting to utilize the "csv-parse" library in Typescript to read a csv file by creating an observable. The code provided uses fs.createReadStream to read the file. I am looking to return the observable and subscribe to it, but it seems that the p ...