【发布时间】:2013-08-22 02:15:23
【问题描述】:
我的要求是我需要替换$ with JQuery,并且我必须动态创建<div/>s。
我需要使用Jquery 显示数据。
请解释一下这个例子的控制流程:
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %>
<portlet:defineObjects />
This is the <b>AjaxApp</b> portlet in View mode.
<script type="text/javascript"
src="/html/js/jquery/jquery.js"></script>
<aui:form>
<aui:input name="pid" label="pid" id="pid"></aui:input>
<aui:button name="getData" value="Get Details"
id="getData"></aui:button>
</aui:form>
<div id="a1"></div>
<div id="a2"></div>
<div id="a3"></div>
<portlet:resourceURL var="resourceURL"></portlet:resourceURL>
<script type="text/javascript">
$("#<portlet:namespace/>getData").click(function() {
var nameVal = jQuery("#<portlet:namespace/>pid").val();
alert('hi'+nameVal);
jQuery.ajax({
url :'<%=resourceURL%>',
data: {pid:nameVal},
type: "POST",
dataType: "json",
success: function(data) {
$("#a").html(data);
document.getElementById("a1").innerHTML="<font color=green>PID
:</font>"+data["pid"];
document.getElementById("a2").innerHTML="<font color=green>Pname:
</font>"+data["pname"];
document.getElementById("a3").innerHTML="<font color=green>Ptype:
</font> "+data["ptype"];
}
});
});
</script>
我是 liferay 和 ajax 的新手。需要帮助来解决此问题?
【问题讨论】:
-
您是否遇到任何错误或只想了解流程?
-
不,我没有收到任何错误!我想用 Jquery 代码替换 document.getElementById!