【发布时间】:2014-03-13 18:50:36
【问题描述】:
我的控制器中有一个方法
def returnJames = {
JSONObject jsonObject = new JSONObject()
jsonObject.put("name","James")
return jsonObject
}
然后我有一个看法:
<html>
<!--import gsp that has all the jquery imports-->
<script>
function changeName()
{
$.ajax({
url:"<g:createLink url="[action:'returnJames',controller:'mycontroller']" />",
dataType: "json",
asnyc: false,
success: function(data) {
$('mytextbox').val(it.name)
}
});
}
</script>
<g:form controller="mycontroller" method="post" >
<g:textField name="mytextbox" value="" />
<button name = "mybutton" id = "mybutton" onclick="changeName()">change name</button>
</g:form>
</html>
但是它只是试图将页面更改为不存在的 mycontroller 控制器的索引视图。我怎样才能让它只用“James”填写文本框?
【问题讨论】:
标签: javascript jquery ajax grails gsp