HTML onchange没有被Ajax插入触发

时间:2016-04-30 21:37:05

标签: javascript jquery html ajax

我是Jquery Ajax的新手。 我有一个jquery ajax函数,它从服务器接收一个值。

            <Image Height="114" HorizontalAlignment="Left" Margin="129,48,0,0" Name="Image1" Stretch="Fill" VerticalAlignment="Top" Width="170" Source="/Tooltip1;component/Images/Desert.jpg" >

<ToolTipService.ToolTip >
            <ToolTip d:DataContext="{d:DesignInstance Type=local:Data}">
                <ListBox x:Name="LstTemp">
                    <ListBox.ItemContainerStyle>

                            <Style TargetType="ListBoxItem">
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate TargetType="ListBoxItem">
                                            <Grid Margin="2">
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="Auto" />
                                                    <ColumnDefinition />
                                                </Grid.ColumnDefinitions>
                                                <CheckBox IsChecked="true" IsEnabled="false"/>
                                                <ContentPresenter
                                Grid.Column="1"
                                Margin="2,0,0,0" />
                                            </Grid>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>

                    </ListBox.ItemContainerStyle>
                </ListBox>
            </ToolTip>
</ToolTipService.ToolTip>
    </Image>

在这里,我从服务器获取data.appid。 我想将它插入到一个html元素#partyID中,插入后我希望onchange事件被触发,这将为我做一些工作。 下面是html。

function servertransfer_reg(datapack1,datapack2,datapack3,datapack4) {
    alert('Start of Ajax Call');
    //Ajax , Jquery Call to Server for sending free time data
    $.ajax({        
        type: "POST",
                dataType: 'json',
        url: "xyz.php",
        data: {M_N : datapack1,
                       Em : datapack2,
                       TandC: datapack3,
                       News: datapack4
                },
        success: function(data) {
                    alert(data.appid);
        $("#server_answer_reg").html('<p>Your App ID Successfully created<p/>' + data.appid);
        //document.getElementById("partyID").innerHTML = data.appid;
        $("#partyID").html(data.appid);
       }
    });

} 

这里,我的saveIDs()函数没有被调用。

我从Ajax调用中收到了预期的数据。

如果您需要更多信息,请与我们联系。

2 个答案:

答案 0 :(得分:0)

当您离开焦点时,onchange将会触发(如果您执行了任何更改)。成功执行后,为什么不在下一行调用saveIDs()函数?我的意思是

success: function(data) {
   alert(data.appid);
   $("#server_answer_reg").html('<p>Your App ID Successfully created<p/>' + data.appid);
   //document.getElementById("partyID").innerHTML = data.appid;
   $("#partyID").html(data.appid);
   saveIDs();
}

答案 1 :(得分:0)

您必须trigger onchange事件。

请参阅:
http://api.jquery.com/trigger/