问题:点击grid中更换按钮后ie8执行成功,正确返回并跳出正确的提示框,chrome执行则跳出错误提示信息,firefox没有任何提示信息,请高手解决
代码
<script type="text/javascript" src="../js/jq.js"></script>
<script language="javascript" type="text/javascript">
function showchange(itemid, zgbm) {
$.ajax({
//要用post方式
type: "Post",
//方法所在页面和方法名
url: "LBChangeAdd.aspx/ChangeItem",
data: "{itemid:"+itemid+",zgbm:"+zgbm+"}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data) {
//返回的数据用data.d获取内容
alert(data.d);
},
error: function(err) {
alert("出错了:"+err);
}
});
}
</script><asp:GridView id="grid" runat="server" AllowPaging="True"
Width="100%" Font-Size="Small"
AutoGenerateColumns="False" EmptyDataText="没有记录"
OnPageIndexChanging="grid_PageIndexChanging" CellPadding="4"
ForeColor="#333333" onrowdatabound="grid_RowDataBound"
>
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#E3EAEB" HorizontalAlign="Center" VerticalAlign="Middle"/>
<columns>
<%-- <asp:BoundField DataField="hidecode" headertext="hidecode"
sortexpression="hidecode" >
<ItemStyle CssClass="hidden" />
<HeaderStyle CssClass="hidden" />
</asp:BoundField>--%>
<asp:ButtonField Text="更换" /> <asp:BoundField DataField="itemid" headertext="itemid"
sortexpression="itemid" >
<ItemStyle CssClass="hidden" />
<HeaderStyle CssClass="hidden" />
</asp:BoundField>
<asp:BoundField DataField="zgbm" headertext="zgbm"
sortexpression="zgbm" >
<ItemStyle CssClass="hidden" />
<HeaderStyle CssClass="hidden" />
</asp:BoundField>
<asp:boundfield datafield="名称" HeaderStyle-Wrap="false" headertext="名称"
ItemStyle-Wrap="false" sortexpression="名称">
<HeaderStyle Wrap="False" />
<ItemStyle Wrap="False" />
</asp:boundfield>
<asp:boundfield datafield="计量单位" HeaderStyle-Wrap="false" headertext="计量单位"
ItemStyle-Wrap="false" sortexpression="计量单位">
<HeaderStyle Wrap="False" />
<ItemStyle Wrap="False" />
</asp:boundfield>
<asp:boundfield datafield="领用时间" HeaderStyle-Wrap="false"
headertext="领用时间" ItemStyle-Wrap="false" sortexpression="领用时间">
<HeaderStyle Wrap="False" />
<ItemStyle Wrap="False" />
</asp:boundfield>
<asp:boundfield datafield="数量" HeaderStyle-Wrap="false" headertext="数量"
ItemStyle-HorizontalAlign="Right" ItemStyle-VerticalAlign="Middle"
ItemStyle-Wrap="false" sortexpression="数量">
<HeaderStyle Wrap="False" /><ItemStyle HorizontalAlign="Right" VerticalAlign="Middle" Wrap="False"></ItemStyle>
</asp:boundfield>
<asp:boundfield datafield="规格" HeaderStyle-Wrap="false" headertext="规格"
ItemStyle-HorizontalAlign="Right" ItemStyle-VerticalAlign="Middle"
ItemStyle-Wrap="false" sortexpression="规格">
<HeaderStyle Wrap="False" /><ItemStyle HorizontalAlign="Right" VerticalAlign="Middle" Wrap="False"></ItemStyle>
</asp:boundfield>
</columns>
<pagertemplate>
<table width="100%">
<tr>
<td style="text-align:left">
第<asp:Label id="lblPageIndex" runat="server" text='<%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>' />页
共/<asp:Label id="lblPageCount" runat="server" text='<%# ((GridView)Container.Parent.Parent).PageCount %>' />页
<asp:linkbutton id="btnFirst" runat="server" causesvalidation="False" commandargument="First" commandname="Page" text="首页" />
<asp:linkbutton id="btnPrev" runat="server" causesvalidation="False" commandargument="Prev" commandname="Page" text="上一页" />
<asp:linkbutton id="btnNext" runat="server" causesvalidation="False" commandargument="Next" commandname="Page" text="下一页" />
<asp:linkbutton id="btnLast" runat="server" causesvalidation="False" commandargument="Last" commandname="Page" text="尾页" />
<asp:textbox id="txtNewPageIndex" runat="server" width="20px" text='<%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>' />
<asp:linkbutton id="btnGo" runat="server" causesvalidation="False" commandargument="-1" commandname="Page" text="GO" /><!-- here set the CommandArgument of the Go Button to '-1' as the flag -->
</td>
</tr>
</table>
</pagertemplate>
<PagerStyle BackColor="#E3EAEB" ForeColor="#000000" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#7C6F57" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView> 后台代码
[System.Web.Services.WebMethod]
public static string ChangeItem(String itemid, String zgbm)
{
return "成功更换!"+itemid+"--"+zgbm;
} protected void grid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
{
int i = 0;
((LinkButton)e.Row.Cells[0].Controls[0]).Attributes.Add("onclick", "javascript:showchange('" + e.Row.Cells[i+1].Text + "','" + e.Row.Cells[i + 2].Text + "')");
}
}
}
代码
<script type="text/javascript" src="../js/jq.js"></script>
<script language="javascript" type="text/javascript">
function showchange(itemid, zgbm) {
$.ajax({
//要用post方式
type: "Post",
//方法所在页面和方法名
url: "LBChangeAdd.aspx/ChangeItem",
data: "{itemid:"+itemid+",zgbm:"+zgbm+"}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data) {
//返回的数据用data.d获取内容
alert(data.d);
},
error: function(err) {
alert("出错了:"+err);
}
});
}
</script><asp:GridView id="grid" runat="server" AllowPaging="True"
Width="100%" Font-Size="Small"
AutoGenerateColumns="False" EmptyDataText="没有记录"
OnPageIndexChanging="grid_PageIndexChanging" CellPadding="4"
ForeColor="#333333" onrowdatabound="grid_RowDataBound"
>
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#E3EAEB" HorizontalAlign="Center" VerticalAlign="Middle"/>
<columns>
<%-- <asp:BoundField DataField="hidecode" headertext="hidecode"
sortexpression="hidecode" >
<ItemStyle CssClass="hidden" />
<HeaderStyle CssClass="hidden" />
</asp:BoundField>--%>
<asp:ButtonField Text="更换" /> <asp:BoundField DataField="itemid" headertext="itemid"
sortexpression="itemid" >
<ItemStyle CssClass="hidden" />
<HeaderStyle CssClass="hidden" />
</asp:BoundField>
<asp:BoundField DataField="zgbm" headertext="zgbm"
sortexpression="zgbm" >
<ItemStyle CssClass="hidden" />
<HeaderStyle CssClass="hidden" />
</asp:BoundField>
<asp:boundfield datafield="名称" HeaderStyle-Wrap="false" headertext="名称"
ItemStyle-Wrap="false" sortexpression="名称">
<HeaderStyle Wrap="False" />
<ItemStyle Wrap="False" />
</asp:boundfield>
<asp:boundfield datafield="计量单位" HeaderStyle-Wrap="false" headertext="计量单位"
ItemStyle-Wrap="false" sortexpression="计量单位">
<HeaderStyle Wrap="False" />
<ItemStyle Wrap="False" />
</asp:boundfield>
<asp:boundfield datafield="领用时间" HeaderStyle-Wrap="false"
headertext="领用时间" ItemStyle-Wrap="false" sortexpression="领用时间">
<HeaderStyle Wrap="False" />
<ItemStyle Wrap="False" />
</asp:boundfield>
<asp:boundfield datafield="数量" HeaderStyle-Wrap="false" headertext="数量"
ItemStyle-HorizontalAlign="Right" ItemStyle-VerticalAlign="Middle"
ItemStyle-Wrap="false" sortexpression="数量">
<HeaderStyle Wrap="False" /><ItemStyle HorizontalAlign="Right" VerticalAlign="Middle" Wrap="False"></ItemStyle>
</asp:boundfield>
<asp:boundfield datafield="规格" HeaderStyle-Wrap="false" headertext="规格"
ItemStyle-HorizontalAlign="Right" ItemStyle-VerticalAlign="Middle"
ItemStyle-Wrap="false" sortexpression="规格">
<HeaderStyle Wrap="False" /><ItemStyle HorizontalAlign="Right" VerticalAlign="Middle" Wrap="False"></ItemStyle>
</asp:boundfield>
</columns>
<pagertemplate>
<table width="100%">
<tr>
<td style="text-align:left">
第<asp:Label id="lblPageIndex" runat="server" text='<%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>' />页
共/<asp:Label id="lblPageCount" runat="server" text='<%# ((GridView)Container.Parent.Parent).PageCount %>' />页
<asp:linkbutton id="btnFirst" runat="server" causesvalidation="False" commandargument="First" commandname="Page" text="首页" />
<asp:linkbutton id="btnPrev" runat="server" causesvalidation="False" commandargument="Prev" commandname="Page" text="上一页" />
<asp:linkbutton id="btnNext" runat="server" causesvalidation="False" commandargument="Next" commandname="Page" text="下一页" />
<asp:linkbutton id="btnLast" runat="server" causesvalidation="False" commandargument="Last" commandname="Page" text="尾页" />
<asp:textbox id="txtNewPageIndex" runat="server" width="20px" text='<%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>' />
<asp:linkbutton id="btnGo" runat="server" causesvalidation="False" commandargument="-1" commandname="Page" text="GO" /><!-- here set the CommandArgument of the Go Button to '-1' as the flag -->
</td>
</tr>
</table>
</pagertemplate>
<PagerStyle BackColor="#E3EAEB" ForeColor="#000000" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#7C6F57" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView> 后台代码
[System.Web.Services.WebMethod]
public static string ChangeItem(String itemid, String zgbm)
{
return "成功更换!"+itemid+"--"+zgbm;
} protected void grid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
{
int i = 0;
((LinkButton)e.Row.Cells[0].Controls[0]).Attributes.Add("onclick", "javascript:showchange('" + e.Row.Cells[i+1].Text + "','" + e.Row.Cells[i + 2].Text + "')");
}
}
}
data: {itemid:itemid,zgbm:zgbm},
或者
data: {itemid:itemid,zgbm:zgbm},
当我用 按钮直接click事件中调用firefox和chrome中都正常
在aspx文件中加入如下代码
function myclick() {
showchange(12, "001234");
}<input type="button" name="btnOK" id="btnOK" value="查询" onclick="myclick()"/>当我点查询按钮时,三浏览器上面的调用能正常返回
async: false,
变成下面如下:
function showchange(itemid, zgbm) {
//if (confirm('你确认要更换吗?'))
//$("#btnOK").click();
$.ajax({
//要用post方式
type: "POST",
//方法所在页面和方法名
url: "LBChangeAdd.aspx/ChangeItem",
async: false,
data: "{itemid:"+itemid+",zgbm:"+zgbm+"}",
contentType: "application/json; charset=utf-8",
processData:false,
//dataType: "json",
success: function(data) {
//返回的数据用data.d获取内容
alert(data.d);
},
error: function(err) {
alert("出错了:"+err);
}
});
}三个浏览器表现正常,奇怪,奇怪!