Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用jquery发送json对象,但在compojure中接收nil_Jquery_Ajax_Json_Clojure_Compojure - Fatal编程技术网

使用jquery发送json对象,但在compojure中接收nil

使用jquery发送json对象,但在compojure中接收nil,jquery,ajax,json,clojure,compojure,Jquery,Ajax,Json,Clojure,Compojure,我正在尝试将json从我的javascript(使用jQueryPost)发送到compojure。我确信我做错了一些简单的事情。我的javascript文件(全部)如下所示: $(document).ready(function() { $.post("/", "foo", function(){}); }); 我的clojure服务器看起来像: (ns spendy.routes (:use compojure.core spendy.core ring

我正在尝试将json从我的javascript(使用jQueryPost)发送到compojure。我确信我做错了一些简单的事情。我的javascript文件(全部)如下所示:

$(document).ready(function() {
    $.post("/", "foo", function(){});
});
我的clojure服务器看起来像:

(ns spendy.routes
  (:use compojure.core
        spendy.core
    ring.middleware.json-params
        [hiccup.middleware :only (wrap-base-url)])
  (:require [compojure.route :as route]
            [compojure.handler :as handler]
            [compojure.response :as response]
        [clj-json.core :as json]))

(defroutes main-routes
  (GET "/" [] (index-page))
  (POST "/" [sent-object]
    (println "got:" sent-object "from jquery")
    (json/generate-string (respond-to-ajax (json/parse-string (if sent-object sent-object "")))))
  (route/resources "/")
  (route/not-found "Page not found"))

(def app
  (-> (handler/site main-routes)
      (wrap-base-url)))
当我加载页面时,我希望得到

从jquery获得:foo

但是我得到了

从jquery获得:nil

发生了什么事

$(document).ready(function() {
    $.post("/", {foo:"foo"}, function(){});
})

在clojure端,您可以通过名称
foo

接收POST变量,我认为您的应用程序定义看起来有点奇怪。您正在调用(处理程序/站点主路由),然后使用其值作为线程宏的形式。我看到的其他路线定义如下所示

(def app 
  (-> main-routes
      wrap-base-url))