How can you make ajax requests?


#1

How can you make ajax requests?


#2

I haven’t done that, but it looks like $.ajax works out of the box.

{$} = require 'atom'
$.ajax
  url: 'http://yourServer.com'
  success: (data) ->
    console.log data

#3

not in the console though. isnt available. I'm not a coffeescript guy tho--how do u do {} = require ‘atom’ in the console?


#4

From the console, you can use this:

require('atom').$.ajax({ url: 'http://urlgoeshere.com', success: function(data) { console.log(data); } });

#5

perfect. thats it. thank you brother.


#6

I just tried this and this no longer works:

require('atom').$.ajax({ url: 'http://urlgoeshere.com', success: function(data) { console.log(data); } });

The way to do it now (based on How to use jQuery inside a package? ) is to replace “atom” with “atom-space-pen-views”:

require('atom-space-pen-views').$.ajax({ url: 'http://urlgoeshere.com', success: function(data) { console.log(data); } })

#7

I had a similar question and found the request promise node module to be very helpful. Made it easy to do things.