我有这个代码:
$.ajax({
dataType: 'text',
url: '/_/js/answers.json',
type: "GET",
success: function (data) {
alert(data);
alert(data.code);
var result = JSON.parse(data);
var hey = JSON.parse('{"code": 123}');
alert(hey.code);
alert(result.code);
},
error: function () {
alert("code not found");
}
});
Run Code Online (Sandbox Code Playgroud)
在第一个警报中,alert(data)
它显示我'{"代码":123}',在第二个警报中alert(data.code)
,它告诉我undefined
,在第三个警报中alert(hey.code)
,它显示了我123
,这就是我想要的,但在第四个警报中,控制台告诉我Uncaught SyntaxError: Unexpected token '
.
当我改变JSON.parse
to时$.parseJSON
,它完全相同.
我不知道什么是错的,json很好(与var中的json完全相同).
我像这样将json传递给服务器:
javascript:
var json = {code: code};
json = JSON.stringify(json);
json = {data: json};
$.ajax({
url: "/_/js/write-json.php",
type: "POST",
dataType: 'json',
data: …
Run Code Online (Sandbox Code Playgroud)
我有这个代码:
function voteNewWindow(mailNum) {
chrome.windows.create({
url: 'http://www.google.com',
incognito: true
}, function (window) {
console.log('created ' + window.id);
chrome.tabs.query({
active: true,
windowId: window.id
}, function (tabs) {
var tab = tabs[0];
chrome.tabs.executeScript(tab.id, {
file: "jquery-2.1.1.min.js"
}, function () {
chrome.tabs.executeScript(tab.id, {
file: "content_script.js"
}, function () {
chrome.tabs.sendMessage(tab.id, {
email: JSON.parse(localStorage.mailList)[mailNum]
}, function (response) {
console.log(response);
chrome.windows.remove(window.id);
console.log('window ' + window.id + " removed");
});
});
});
});
});
}
function execute() {
for (var i = 0; i < JSON.parse(localStorage.mailList).length; …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Web Audio API 找到音频时刻的强度。我在规范中发现的唯一与强度相关的事情是:
analyser.minDecibels
analyser.maxDecibels
Run Code Online (Sandbox Code Playgroud)
有没有办法做到这一点?
javascript ×3
ajax ×1
asynchronous ×1
audio ×1
html5-audio ×1
jquery ×1
json ×1
promise ×1
syntax-error ×1