JQuery Ajax Returning 404 When Method = Post

So I have an ajax script that runs, it looks like this:

            jQuery.ajax({
                url: '
                type: 'POST',
                data: { name : 'name2' },
                success: function (data) {
                    alert(data);
                },
                error: function(xhr, desc, err) {
                    console.log(xhr);
                    console.log("Details0: " + desc + "\nError:" + err);
                },
            }); 

This runs fine but returns a 404 from the page set as the 'url' If I remove 'type: post'

3

3 Answers

Here your method: 'Post', Type is something what you want to get in return like text

 jQuery.ajax({
                url: '
                method: 'POST',
                data: { name : 'name2' },
                success: function (data) {
                    alert(data);
                },
                error: function(xhr, desc, err) {
                    console.log(xhr);
                    console.log("Details0: " + desc + "\nError:" + err);
                },
            }); 
12

If type: 'POST' is omitted, jQuery is treating it like a GET request, which it defaults to see the docs, where the resource may not exist therefore resulting in a the 404 you're seeing.

1

It turns out I forgot to add the name="" parameter in my input types. Doh!

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Elena Rostova

Elena Rostova

Lead Health, Wellness & Medical Journalist

Elena Rostova holds a Master's degree in Public Health Journalism. She covers groundbreaking medical research, holistic wellness trends, mental health awareness, and nutritional science.

Share this article
Twitter Facebook Pinterest