0

I have tried ,but I got error.

(Failed to load resource: the server responded with a status of 405 (Method Not Allowed))

json file is dataJSON.js

items: [
    {
        empid:2192,
        name:"hari",
        designation: "software engineer"
    },
    {
        empid: 2392,
        name: "bala",
        designation: "software engineer"
    }
],

AJAX call :

 $.ajax({
    type: "POST",
    url: "dataJSON.js",
    contentType: "application/json; charset=utf-8",
    datatype: "json",
    data: {},
    success: function (response) {
        alert('test');
    }       
});

please tell some the solution, I think url is a problem. How to use js file into the ajax url ?

4
  • i think you should change the type to get not post Commented Nov 3, 2014 at 10:04
  • First, i think you are just trying to 'read' data, why not use "GET"? As for the url, where (at which url) is the data loaded from the server? The way you are specifying it looks alright. Commented Nov 3, 2014 at 10:05
  • You better use a GET than a POST to get things. That said this doesn't explain this specific error message which generally occurs when trying to use a more uncommon method like DELETE. Is your JS file located in the same location aas your HTML file ? Commented Nov 3, 2014 at 10:07
  • datatype should be dataType see $.ajax docs Commented Nov 3, 2014 at 10:34

1 Answer 1

1

The url is ok, if there is issue with the url, it would send 404 error. Try using get request.

$.ajax({
    type: "GET",
    url: "dataJSON.js",
    contentType: "application/json",
    dataType: "json",
    data: {},
    success: function (response) {
        alert('test');
    }       
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.