मैं इस कोड को निष्पादित कर रहा हूं:
var element=null;
$.ajax({
type: "GET",
async: false,
url: "C:UsersmyDirDesktopProjectjsonfile.json",
dataType: "json",
success : function(data) {
element=data;
}
});
JSON संरचना:
{
"info":[
{
"a1": "Ram",
"b1": "P123"
},
{
"a1": "ROM",
"b1": "P245"
}
]
}
लेकिन मुझे चर में कुछ भी नहीं मिल रहा है
उत्तर:
जवाब के लिए 0 № 1Ajax का उपयोग करते हुए किसी भी त्रुटि के लिए जाँच करें
var element=null;
$.ajax({
type: "GET",
async: false,
url: "jsonfile.json",//Edited
dataType: "json",
success : function(data) {
element=data;
}
error: function(jqXHR, textStatus, errorThrown) {
console.log(textStatus, errorThrown);
}
});
उत्तर № 2 के लिए -1
फ़ाइल के लिए अनुमति समस्या हो सकती है। अपने सभी अन्य कोड फ़ाइलों के साथ json फ़ाइल डालें और url में सापेक्ष पथ दें
$.ajax({
type: "GET",
async: false,
url: "jsonfile.json",
dataType: "json",
success : function(data) {
element=data;
}
});
// json फ़ाइल का स्थान वही है जो फ़ाइल ajax कॉल कर रही है