Peter Abraham
Peter Abraham

Reputation: 81

how to access json file using jquery AJAX method

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 ?

Upvotes: 0

Views: 1568

Answers (1)

Indranil Mondal
Indranil Mondal

Reputation: 2857

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');
    }       
});

Upvotes: 1

Related Questions