2012-04-03 66 views
2

我打破我的头试图从一个按钮元素调用一个js函数形式里面,这里是我的代码:合金UI问题javascript函数

<% 
PortletPreferences prefs = renderRequest.getPreferences(); 
String employee = (String)prefs.getValue("name", "New Employee"); 
%> 

<portlet:actionURL var="callURL" windowState="<%=LiferayWindowState.EXCLUSIVE.toString() %>" /> 

<script type="text/javascript"> 
    Liferay.provide(window, 'insertEmployee', 
    function() 
     { 
      var A = AUI(); 
      var url = 'http://localhost:8080/c/portal/json_Service'; 
      A.io.request(url, 
       { 
        method:'POST', 
        data: 
        { 
         serviceClassName: 'com.liferay.test.service.TrabajadorServiceUtil', 
         serviceMethodName: 'create', 
         servletContextName: 'TrabajadorPlugin-portlet', 
         serviceParameters: '[param]', 
        }, 
        headers: {'Content-Type':'charset=utf-8'}, 
        on: 
        { 
         success: function() 
         { 
          alert("success " + responseData.name); 
         } 
        }, 
        form: {id: 'postForm'}, 
        xdr: {dataType: 'json'} 
       }); 
     }, 
     ['aui-io'] 
    ); 
</script> 

<div> 
    <aui:form name="postForm" id="postForm" method="post" onSubmit="insertEmployee();"> 
     <input type="text" name="param" value="<%=employee %>"/> 
     <input type="submit" value="Submit"/> 
    </aui:form> 
</div> 

我没有使用Java类,因此我也没有使用portlet:actionURL。

我的意图是在单击“提交”按钮时调用“insertEmployee()”,但它只发送用户在文本字段内插入的参数。我试图将'onsubmit'也放入提交输入中,但给出了相同的结果。

如果你能帮助我或指导我解决问题,那就太好了!我在互联网上找不到好的信息/内容,我不确定问题出在哪里,还有什么我需要知道。

非常感谢!

+0

我想问题是在

,但我尝试了一切我在我的脑海中......请帮助! – agapitocandemor 2012-04-03 14:04:16

回答

1

我只需要:

<aui:script> 
window.functionName = function() 
{ 
//code 
}; 
</aui:script> 

和调用它:

<aui:form name="myform" action="javascript:functionName();"> 
<aui:input type="submit" name="Submit" value="Update"/> 
</aui:form> 

和功能正在从表单标签调用。