Skip to content

Instantly share code, notes, and snippets.

@cognitom
Created May 22, 2014 14:16
Show Gist options
  • Select an option

  • Save cognitom/9e99b1125d9a3484d22b to your computer and use it in GitHub Desktop.

Select an option

Save cognitom/9e99b1125d9a3484d22b to your computer and use it in GitHub Desktop.
PhantomJSでAjax結果を取得する ref: http://qiita.com/cognitom/items/123f1d0e0d8e3a2ed936
page = (require 'webpage').create()
url = '#'
page.open "http://localhost:3000/", ->
page.evaluate (url) ->
$.ajax url: url, success: (str) -> window.ajaxResult = str
, url
timer = ->
result = page.evaluate -> window.ajaxResult
unless result
window.setTimeout timer, 500 # 500ms ごとにポーリングして確認
else
console.log result
phantom.exit()
timer()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment