Use xhr.responseType = 'json'.
This commit is contained in:
parent
2ed498813d
commit
710655f13e
@ -47,6 +47,8 @@ $.ajax = do ->
|
||||
if whenModified
|
||||
r.setRequestHeader 'If-Modified-Since', lastModified[url] if url of lastModified
|
||||
$.on r, 'load', -> lastModified[url] = r.getResponseHeader 'Last-Modified'
|
||||
if /\.json$/.test url
|
||||
r.responseType = 'json'
|
||||
$.extend r, options
|
||||
$.extend r.upload, upCallbacks
|
||||
r.send form
|
||||
|
||||
@ -37,7 +37,7 @@ Redirect =
|
||||
return if lastarchivecheck > now - 2 * $.DAY
|
||||
$.ajax '<%= meta.page %>json/archives.json', onload: ->
|
||||
if @status is 200
|
||||
Conf['archives'] = JSON.parse @response
|
||||
Conf['archives'] = @response
|
||||
Redirect.selectArchives()
|
||||
$.set
|
||||
lastarchivecheck: now
|
||||
|
||||
@ -61,7 +61,7 @@ ThreadHiding =
|
||||
$.cache "//a.4cdn.org/#{g.BOARD}/threads.json", ->
|
||||
return unless @status is 200
|
||||
threads = {}
|
||||
for page in JSON.parse @response
|
||||
for page in @response
|
||||
for thread in page.threads
|
||||
if thread.no of hiddenThreadsOnCatalog
|
||||
threads[thread.no] = hiddenThreadsOnCatalog[thread.no]
|
||||
|
||||
@ -75,7 +75,7 @@ class DataBoard
|
||||
return
|
||||
board = @data.boards[boardID]
|
||||
threads = {}
|
||||
for page in JSON.parse e.target.response
|
||||
for page in e.target.response
|
||||
for thread in page.threads
|
||||
if thread.no of board
|
||||
threads[thread.no] = board[thread.no]
|
||||
|
||||
@ -114,7 +114,7 @@ Get =
|
||||
"Error #{req.statusText} (#{req.status})."
|
||||
return
|
||||
|
||||
posts = JSON.parse(req.response).posts
|
||||
{posts} = req.response
|
||||
Build.spoilerRange[boardID] = posts[0].custom_spoiler
|
||||
for post in posts
|
||||
break if post.no is postID # we found it!
|
||||
@ -145,7 +145,7 @@ Get =
|
||||
Get.insert post, root, context
|
||||
return
|
||||
|
||||
data = JSON.parse req.response
|
||||
data = req.response
|
||||
if data.error
|
||||
$.addClass root, 'warning'
|
||||
root.textContent = data.error
|
||||
|
||||
@ -239,7 +239,7 @@ Index =
|
||||
|
||||
try
|
||||
if req.status is 200
|
||||
Index.parse JSON.parse(req.response), pageNum
|
||||
Index.parse req.response, pageNum
|
||||
else if req.status is 304 and pageNum?
|
||||
Index.pageNav pageNum
|
||||
catch err
|
||||
|
||||
@ -135,7 +135,7 @@ ImageExpand =
|
||||
# XXX CORS for i.4cdn.org WHEN?
|
||||
$.ajax "//a.4cdn.org/#{post.board}/res/#{post.thread}.json", onload: ->
|
||||
return if @status isnt 200
|
||||
for postObj in JSON.parse(@response).posts
|
||||
for postObj in @response.posts
|
||||
break if postObj.no is post.ID
|
||||
if postObj.no isnt post.ID
|
||||
clearTimeout timeoutID
|
||||
|
||||
@ -41,7 +41,7 @@ ImageHover =
|
||||
# XXX CORS for i.4cdn.org WHEN?
|
||||
$.ajax "//a.4cdn.org/#{post.board}/res/#{post.thread}.json", onload: ->
|
||||
return if @status isnt 200
|
||||
for postObj in JSON.parse(@response).posts
|
||||
for postObj in @response.posts
|
||||
break if postObj.no is post.ID
|
||||
if postObj.no isnt post.ID
|
||||
clearTimeout timeoutID
|
||||
|
||||
@ -74,13 +74,12 @@ ExpandThread =
|
||||
a.textContent = "Error #{req.statusText} (#{req.status})"
|
||||
return
|
||||
|
||||
data = JSON.parse(req.response).posts
|
||||
Build.spoilerRange[thread.board] = data.shift().custom_spoiler
|
||||
Build.spoilerRange[thread.board] = req.response.posts.shift().custom_spoiler
|
||||
|
||||
posts = []
|
||||
postsRoot = []
|
||||
filesCount = 0
|
||||
for postData in data
|
||||
for postData in req.response.posts
|
||||
if post = thread.posts[postData.no]
|
||||
filesCount++ if 'file' of post
|
||||
postsRoot.push post.nodes.root
|
||||
|
||||
@ -41,10 +41,9 @@ ThreadStats =
|
||||
whenModified: true
|
||||
onThreadsLoad: ->
|
||||
return if @status isnt 200
|
||||
pages = JSON.parse @response
|
||||
for page in pages
|
||||
for page in @response
|
||||
for thread in page.threads
|
||||
if thread.no is ThreadStats.thread.ID
|
||||
ThreadStats.pageCountEl.textContent = page.page
|
||||
(if page.page is pages.length - 1 then $.addClass else $.rmClass) ThreadStats.pageCountEl, 'warning'
|
||||
(if page.page is @response.length - 1 then $.addClass else $.rmClass) ThreadStats.pageCountEl, 'warning'
|
||||
return
|
||||
|
||||
@ -98,7 +98,7 @@ ThreadUpdater =
|
||||
switch req.status
|
||||
when 200
|
||||
g.DEAD = false
|
||||
ThreadUpdater.parse JSON.parse(req.response).posts
|
||||
ThreadUpdater.parse req.response.posts
|
||||
ThreadUpdater.setInterval()
|
||||
when 404
|
||||
g.DEAD = true
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user