title: Using jquery ajax post to submit a POST request in Phoenix Framework
body: <p>We want to use our content editable, taking advantage of the generated routes with the following in router.ex:</p>
  
  <pre><code>  pipeline :browser do
      plug :accepts, ["html"]
      plug :fetch_session
      plug :fetch_flash
      plug :put_secure_browser_headers
    end
  
    pipeline :api do
      plug :accepts, ["json"]
    end
    scope "/", TextEditor do
      pipe_through :browser # Use the default browser stack
  
      get "/", PageController, :index
      resources "/posts", PostController
    end
  </code></pre>
  
  <p>and the controller functions, namely create:</p>
  
  <pre><code>  def create(conn, %{"post" =&gt; post_params}) do
      changeset = Post.changeset(%Post{}, post_params)
  
      case Repo.insert(changeset) do
        {:ok, _post} -&gt;
          conn
          |&gt; put_flash(:info, "Post created successfully.")
          |&gt; redirect(to: post_path(conn, :index))
        {:error, changeset} -&gt;
          render(conn, "new.html", changeset: changeset)
      end
    end
  </code></pre>
  
  <p>However we don't want to use the generated form, we are then attempting to test this with divs and the jquery method $.post:</p>
  
  <pre><code>&lt;div id="newPost" contenteditable="true"&gt;write here&lt;/div&gt;
  &lt;div id="button" class="btn btn-primary"&gt;Save&lt;/div&gt;
  
  &lt;script type="text/javascript"&gt;
  $(document).ready(function(){
    $("#button").click(function() {
      var post = $("#newPost").html();
  
      $.post( "/posts/post", { title: post })
       .done(function() {
          alert( "Data Loaded: " );
      });
    });
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>However we are not getting the alert or any data inserted into our database.
  What are we missing?</p>
  
  <p>EDIT: In the browser pipeline we removed the cross forgery plug because of a csrf token error.</p>