Created
July 21, 2011 22:43
-
-
Save mjg123/1098417 to your computer and use it in GitHub Desktop.
How to make a json(p) request from ClojureScript using jQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def jquery (js* "$")) | |
(defn show [msg] | |
(let [data-as-json ((js* "JSON.stringify") msg nil 4)] | |
((js* "alert") data-as-json))) | |
(defn make-js-map | |
"makes a javascript map from a clojure one" | |
[cljmap] | |
(let [out (js-obj)] | |
(doall (map #(aset out (name (first %)) (second %)) cljmap)) | |
out)) | |
(defn doajax [] | |
(.ajax jquery | |
"http://api.stackoverflow.com/1.1/users/268619" | |
(make-js-map | |
{:success show | |
:dataType "jsonp" | |
:jsonp "jsonp"}))) | |
(.ready (jquery (js* "document")) | |
doajax) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script> | |
<script type="text/javascript" src="hello.js"></script> | |
</head> | |
<body> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks mate....;)