編集:最新情報は投稿の下部にあります。AJAX PageMethodsはルーティングと競合していますか?
__doPostBackを使用してポストバックを強制するページに更新パネルがあります。私はできるだけ早く私は、ポストバックが発生しない/otherpath/page
のようなルートでページにアクセスすると、しかし/path/page.aspx.
でそれを参照するとき
すべてが正常に動作します。
提案がありますか?
/// <reference name="MicrosoftAjax.js"/>
function Check() {
// Call the static page method.
PageMethods.GetLatestHeadlineTick(OnSucceeded, OnFailed);
}
function OnSucceeded(result, userContext, methodName) {
// Parse the page method's result and the embedded
// hidden value to integers for comparison.
var LatestTick = parseInt(result);
var LatestDisplayTick = parseInt($get('LatestDisplayTick').value);
// If the page method's return value is larger than
// the embedded latest display tick, refresh the panel.
if (LatestTick > LatestDisplayTick)
__doPostBack('UpdatePanel1', '');
// Else, check again in five seconds.
else
setTimeout("Check()", 5000);
}
// Stub to make the page method call happy.
function OnFailed(error, userContext, methodName) { }
function pageLoad() {
// On initial load and partial postbacks,
// check for newer articles in five seconds.
setTimeout("Check()", 5000);
}
そして、私のマークアップ:
コードビハインドで<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="True">
<Scripts>
<asp:ScriptReference Path="/resources/js/bus-times.js" />
</Scripts>
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" ClientIDMode="Static">
<ContentTemplate>
<asp:GridView ID="gvSchedule" runat="server" AutoGenerateColumns="False" Width="80%">
<AlternatingRowStyle CssClass="altrowstyle" />
<HeaderStyle CssClass="headerstyle" />
<RowStyle CssClass="rowstyle" />
<Columns>
<asp:BoundField DataField="RouteName" HeaderText="Route" />
<asp:BoundField DataField="TimeTillDeparture" HeaderText="Departs In" />
<asp:BoundField DataField="ScheduledDepartureTime" HeaderText="Est. Departure Time" />
</Columns>
<EmptyDataTemplate>
Data is currently unavailable.
</EmptyDataTemplate>
</asp:GridView>
<div class="updatedstyle">
Last updated:
<asp:Label ID="updated_time" runat="server" ></asp:Label></div>
<asp:HiddenField runat="server" ID="LatestDisplayTick" ClientIDMode="Static" />
<asp:HiddenField runat="server" ID="hf_stopID" ClientIDMode="Static" />
</ContentTemplate>
</asp:UpdatePanel>
とAjax方法:
<WebMethod()> _
Public Shared Function GetLatestHeadlineTick() As Long
Dim stopID As String
If HttpContext.Current.Request.QueryString("stop_id") <> Nothing Then
stopID = HttpContext.Current.Request.QueryString("stop_id")
Else
stopID = "678036"
End If
' Retrieve the cached DataTable.
Dim dt_added As DateTime = CType(BusScheduleService.GetBusDataDateAdded(stopID), DateTime)
' Return that bus data timestamp, in ticks.
Return dt_added.Ticks
End Function
はEDIT:
ここは、私のJSファイルであります
ここはフィドラーの写真です。一番上に作業バージョンがあり、一番下にエラーがあります。 405要求を返します。だから、Ajaxリクエストは解決されたときに実際のルート名として解釈されているようですが、そのルートは存在しないので動作しません。どうすればこの問題を回避できますか? /それはAjaxが、それはURLの後に指定/ functionNameをでそうする関数を呼び出すときのように思えるが、これを模倣ルートの構文...
だからAJAXを経由して/パスGetLatestHeadLineTickを呼び出そうとした場合page.aspx/GetLatestHeadLineTick、それは動作します。しかしルートでは、/ otherpath/page/GetLatestHeadLineTickに行きます。私のサイトはAJAXリクエストではなくルートとしてそれを処理しようとしています。
リクエストに応じて、コンテンツタイプはJSONですが、失敗したリクエストではHTMLとして解釈されています。
あなたのルーティングは正しいですか?投稿しようとしているページに移動できますか?それはPOSTを妨げるのでしょうか? –
@DustinDavisはいルートは正しいです。私はページにうまく行くことができます。私はそれがJavaScriptを介してPOSTを防止していると仮定しますが、ページ上の他のボタンや他の機能は、適切にポストバックします。 – SventoryMang
POSTを実行するために使用しているjavascriptを投稿してください。可能であれば、投稿をしているときにフィドラーや火かき棒を見ることで得られる情報を提供してください。 –