$ .get()在获取JSON文件时返回字符串(仅在Mac中) [英] $.get() returns string while fetching JSON file (Only in Mac)

查看:75
本文介绍了$ .get()在获取JSON文件时返回字符串(仅在Mac中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的JSON是标准键值对,例如

My JSON is a standard key value pair e,g

{"key1":"val1","key2":"val2"}

在一个单独的文件中,并使用

in a separate file, and is fetched using

$.get()

预期的响应数据类型为JSON.但是,对于Mac,响应的数据类型为String.

The datatype of the response as expected is in JSON. But, in case of mac, the datatype of the response is String.

我需要帮助以找出这种差异的原因.

I need help to figure out why is this discrepancy.

PS-通过在数据类型检查中使用"if"语句可以轻松解决此问题.这个问题是要弄清楚为什么会发生这种数据类型更改.

PS - This issue can easily be resolved by "if" statement on datatype check. This question is to figure out why such datatype change could occur.

推荐答案

尝试一下$ .getJSON()

Try this $.getJSON()

此方法用于通过AJAX HTTP GET请求获取JSON数据参数url是必填项,data是可选的,success(data,status,xhr)是可选的数据是来自服务器的响应,状态用于成功,错误,超时,并且xhr是对象XMLHttpRequest

This method used to get JSON data using an AJAX HTTP GET request Parameter url is must Required ,data is Optional,success(data,status,xhr) is Optional data is response from the server and status is used for success,error,timeout and xhr is object XMLHttpRequest

这篇关于$ .get()在获取JSON文件时返回字符串(仅在Mac中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆