title: Scala action is not executing to store json object on ajax Submit into Postgresql database using Play Framework and Scala?
body: <p>I have one json object in my view page(index.coffee), that I am sending to Scala controller class to store in Postgresql database through jQuery/ajax, after clicking my Submit button. I have done the following:(controller, model and database table), but I am not seeing any json data in database table after clicking of Submit button, even I cannot see any error  and my println() message on console(I hope addJson() action is not executing).I am not sure what and where I am doing wrong in my entire code from all the files ? As my Play Framework server(2.2.3) is connected to my database(I can see the message on console saying that: [info] play - database [default] connected at: jdbc:postgresql://localhost:5432/mydb).Please let me know where I am doing wrong and thanks in advance.</p>
  
  <p>app.scala:</p>
  
  <pre><code>package controllers
  import play.api.mvc._
  import play.libs.Json;
  import com.fasterxml.jackson.databind.JsonNode;
  import play.api._
  import play.api.mvc.Request
  import play.api.libs.json._
  import play.api.mvc.AnyContent;
  import play.libs.Json;
  import com.fasterxml.jackson.databind.JsonNode;
  import anorm._
  import play.api.data.Form
  import play.api.data.Forms.{single, nonEmptyText}
  import play.api.data._
  import play.api.data.Forms._
  import play.api.mvc.{Action, Controller}
  import anorm.NotAssigned
  import models.Jsoncontent
  import play.api.Play.current
  import views._
  import models._
  
  class Application extends Controller {
  
   //def saveJsonData = Action { request =&gt;
    //val body: AnyContent = request.body
    //val jsonBody: Option[JsValue] = body.asJson
    //jsonBody.map {json =&gt;
    //jsonBody.map {dao =&gt;
     //dao.persist(json) 
     //Ok("Saved") 
   // }}.getOrElse {
     // BadRequest("Expecting text/json request.body") 
   // }
    //}
  
  
  val jsonForm = Form(
      single("content" -&gt; nonEmptyText)
    )
  
    def addJson() = Action { implicit request =&gt;
    println("Inside addJson() ... !")
      jsonForm.bindFromRequest.fold(
        errors =&gt; BadRequest,
        {
          case (content) =&gt;
            Jsoncontent.create(Jsoncontent(NotAssigned, content))
            Redirect(routes.Application.index())
        }
      )
    }
  
  }
  </code></pre>
  
  <p>Jsoncontent.scala:</p>
  
  <pre><code>package models
  
  import anorm._
  import anorm.SqlParser._
  import play.api.db._
  import play.api.Play.current
  import play.api.libs.json.{Json,JsValue}
  import anorm.features.parameterWithUntypedName
  
  case class Jsoncontent (
    id: Pk[Long], content: String
  )
  
  object Jsoncontent {
    val extractor = {
      get[Pk[Long]]("id") ~
      get[String]("content") map {
        case id~content =&gt; Jsoncontent(id, content)
   }
   }
  
    def create(jsondata: Jsoncontent): Unit = {
      DB.withConnection { implicit connection =&gt;
        SQL("INSERT INTO jsondata(content) VALUES({content})").on(
          'content -&gt; jsondata.content
        ).executeInsert()
      }
    }
  }
  </code></pre>
  
  <p>index.coffee:</p>
  
  <pre><code>do -&gt;
    jsonContent = {}
    $('input[id=buttonId]').click -&gt;
      name = $(this).attr('name')
      jsonContent[name] = $(this).val()
      return
    $('#submit').click -&gt;
      $('input[id=fileId]').each ($i) -&gt;
        name = $(this).attr('name')
        jsonContent[name] = $(this).val()
        $.ajax
        type: 'POST'
        contentType: 'application/json; charset=utf-8'
        dataType: 'json'
        url: '/addJson'
        data: JSON.stringify(jsonContent)
        success: (data) -&gt;
          alert 'data saent' +data
          console.log data
          return
        error: (XMLHttpRequest, textStatus, errorThrown) -&gt;
          alert 'error found'
          return
        return
      console.log JSON.stringify(jsonContent)
      return
    return
  </code></pre>
  
  <p>routes:</p>
  
  <pre><code>POST    /addJson                    @controllers.Application.addJson
  </code></pre>
  
  <p>table:</p>
  
  <pre><code>CREATE TABLE jsondata (
    id                        serial PRIMARY KEY,
    content                   json NOT NULL
  );
  </code></pre>