嗨 iam 第一次在 asp.net 中使用 JSON。
我的 aspx 代码:
<script type="text/javascript">
$('#imgbtnGo').click(function () {
alert("Hi");
var valService = $("#ddlService").val();
alert("valService"+ valService);
$.ajax({
type: "GET",
url: "/VoyageOneService.svc/BindVoyageDetails?valService =" + valService,
contentType: "application/json; charset=utf-8",
dataType: "Json",
processdata: true,
success: function (msg) {
ServiceSucceeded(msg);
},
error: ServiceFailed
});
});
function ServiceSucceeded(result) {
alert(result);
}
</script>
和
<asp:DropDownList ID="ddlService" runat="server" Width="100px" TabIndex="1"></asp:DropDownList>
<asp:ImageButton ID="imgbtnGo" runat="server" ImageUrl="~/image_repository/go_icon.png" />
<asp:ScriptManagerProxy ID="ScriptProxyVoy" runat="server">
<Services>
<asp:ServiceReference Path="~/VoyageOneService.svc" />
</Services>
</asp:ScriptManagerProxy>
..
我的服务是:
public string BindVoyageDetails(int serviceid)
{
/// Coding here..
Serialization
MemoryStream stream = new MemoryStream();
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(VoyageMaster));
serializer.WriteObject(stream, objVoyMstr);
stream.Position = 0;
StreamReader streamReader = new StreamReader(stream);
return streamReader.ReadToEnd();
}
我希望我在服务方面很完美,但是当我点击我的按钮时,我并没有触发该服务....
我找不到原因,请任何人帮忙