如何将javascript数组发送到Java servlet

时间:2016-01-27 09:21:27

标签: javascript ajax servlets

大家好,我正在做一些正统的Web应用程序,我的方法是使用java和javascript的AJAX。

我问我是否可以设置从javascript到Servlet的数组。

1 个答案:

答案 0 :(得分:-1)

是的,这是可能的!

<UserControl
    x:Class="XamlPullToRefresh.MyUserControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:XamlPullToRefresh"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300"
    d:DesignWidth="400">

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition />
            <RowDefinition />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>

        <Image Source="{Binding myObject.imageUrl}" />
        <TextBlock Grid.Column="1" Text="{Binding myObject.name}" />
        <TextBlock Grid.Row="1" Grid.ColumnSpan="2" Text="{Binding myObject.text}" />
        <StackPanel Grid.Row="2" Grid.ColumnSpan="2" Orientation="Horizontal" HorizontalAlignment="Center">
            <Button Margin="10"/>
            <Button Margin="10"/>
            <Button Margin="10"/>
        </StackPanel>
    </Grid>
</UserControl>

在servlet中:

var test = [];
$.ajax({
    type: 'get', 
    url: 'someurl',
    dataType: 'JSON',
    data: { 
      test: JSON.stringify(test) 
    },
    success: function(data) {

    },
    error: function(data) {
        alert('fail');
    }
});
相关问题