Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; utility function to take a url, replace the $0..$n in the url with entities from params & call GET on it
- ; yeah, it does all that.
- ; FIRST USEFUL CLOJURE/SCRIPTJURE MACRO! w00000t!
- (defjsmacro access [url & params]
- (var url (clj url))
- (clj
- (loop [l (range (count params)) blah (list) params `~params]
- ;(swap! blah conj '(+ 4 5))
- ;(println blah)
- (if (not-empty l)
- (recur
- (rest l)
- (cons `(set! ~(symbol "url") (.replace ~(symbol "url") ~(str "$" (first l)) ~(first params))) blah)
- (rest params))
- (cons 'do blah))))
- (var jqXHR (.ajax $ {:type "GET" :url url}))
- (set! jqXHR.success (fn [data]
- (if (= data.status "failed")
- (.log console data.msg)))))
- ; call like this
- (js (access "/url/$0/$1/$2/" param0 param1 param3))
- ; It can have any number of parameters. It will take care of all that annoying AJAX crap :)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement