我正在尝试将数组(globalaProviders)内容分配给asp隐藏字段(aProvidersHdn),并在单击WebLinkButton(自定义控件)后获取服务器中的值。
在下面的Javascript代码中,我能够将JSON文件中的字符串值分配给globalaProviders数组。当我尝试将数组中的值分配给隐藏字段(aProvidersHdn)时,我在客户端中获取一个空值,从而获得服务器。
以下是JavaScript代码:
<script language="javascript" type="text/javascript">function bbPlusPullTest()
{
globalaProviders=[];
aProvidersHdn="";
$.each(providers, function(i,v){
globalaProviders[i,0]=v.uri;
globalaProviders[i,1]=v.name;
globalaProviders[i,2]=v.description;
});
$("#<%=aProvidersHdn.ClientID%>").val(globalaProviders);
alert("aProvidersHdn = "+ aProvidersHdn);
//empty value obtained
}
</script>
//I’ve added this to trigger a postback after the WebLinkButton(custom control) is clicked so the values of the hidden field can be send to the server.
<% if (!Page.IsPostBack) { %>
<script type="text/javascript">
window.onload = function() {
__doPostBack("<%= MedicalHistory.ClientID %>", "");
}
</script>
这是隐藏字段的分配:ASPX
<asp:HiddenField ID="aProvidersHdn" runat="server" />
//Custom Control Does not has a Click event
<cc1:WebLinkButtonControl ID="MedicalHistory" Key="viewccd" PostBackUrl="BBPlusPullTest.aspx" CssClass="panelitem" runat="server"></cc1:WebLinkButtonControl>
以下是SERVER中的代码
if (!IsPostBack)
{
MedicalHistory.Attributes.Add("onclick", "bbPlusPullTest(); return false;");
}
else
{
string providersArray = aProviders.Value;
}
以下是提供商的代码:
providers = function(registries, callback){
var requests = [];
jQuery.each(registries, function(i, r){
requests.push(jQuery.ajax({
type: "GET",
url: r+"prov.json"
}));
});
var providers = [];
jQuery.when.apply(null, requests).then(function(){
jQuery.each(arguments, function(responseNum, arg){
if (responseNum>=requests.length) {
return;
}
jQuery.each(arg, function(i, provider){
providers.push(provider);
});
});
callback(providers);
});
我做错了什么?
答案 0 :(得分:0)
只需使用一些分隔符连接数组中的字符串即可 然后在服务器端通过此分隔符拆分结果字符串