AJAX POST问题 - [[NoSuchElementException:None.get]]

时间:2012-06-25 02:26:42

标签: scala playframework

我似乎无法通过AJAX javascript POST获取POST参数。错误是:

@6angl7689 - Internal server error, for request [POST /myRoute] ->

play.core.ActionInvoker$$anonfun$receive$1$$anon$1: Execution exception [[NoSuchElementException: None.get]]

路线:

POST    /myRoute  controllers.Application.testPost 

控制器代码:

def myForm = Form(
    tuple(
      "valOne" -> text,
      "valTwo" -> text))

def testPost() = Action { implicit request =>

    val (valOne, valTwo) = myForm.bindFromRequest.get // Errors here

    println("valOne: " + valOne)
    println("valTwo: " + valTwo)

    Ok
}

CoffeeScript客户端:

params = 
   valOne: 'valOne'
   valTwo: 'valTwo'

$.ajax
   type: 'POST'
   url: '/myRoute'
   data: params

1 个答案:

答案 0 :(得分:0)

更新您的客户端代码,

$.ajax(
   type: 'POST'
   url: '/myRoute'
   data: {valOne: 'valOne', valTwo: 'valTwo'}
);

这应该有效