Home  >  Article  >  Web Front-end  >  How can jQuery read local json files

How can jQuery read local json files

php中世界最好的语言
php中世界最好的语言Original
2017-12-30 17:27:263535browse

What I bring to you this time is how to read local json files in jQuery. This is a very easy-to-use and practical guide. This article will give you a good analysis.

I implemented it directly using jquery, but Ajax can also be used, but I use a simplified version of Ajax. $.getJSON(url,function);

function getScenemapData(){
var jsondata={};
$.getJSON("../server/php/files/scenedesc.json", function (data,status){
console.log(“是是不是成功读到数据”+status);
if( status=='success'){
jsondata = data;
//在这里可以调用函数
dosomething();
return jsondata;
}else{
console.log("没有读取到本地文件:"+status);
return false;
}
})
}

status: This parameter is the demonstration userstatus. If the json data is successfully blocked, success will be returned. If the return amount is not IDE, , it means there is a problem, you can find the reason according to the printing status!


I believe you have mastered the method after reading the above introduction. For more exciting information, please pay attention to the php Chinese website Other related articles!

Related reading:

What does the JS engine look like when running

How does native JS implement AJAX and JSONP

How to solve the format of ajax unit seconds when parsing json data

The above is the detailed content of How can jQuery read local json files. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn