Skip to main content

This is documentation for Caché & Ensemble. See the InterSystems IRIS version of this content.Opens in a new tab

For information on migrating to InterSystems IRISOpens in a new tab, see Why Migrate to InterSystems IRIS?

ブラウザへのコードの送信

ブラウザへコードを送信するには、AddShow メソッドを使用します。AddShow メソッドのようなサーバ側のメソッドを呼び出すとき、ブラウザによる実行に使用するコードを返すことができます。この場合、JavaScript の 1 行を返します。このコードは、注文フレームのロケーション・プロパティを参照します。 location プロパティは、そのフレームで表示されるページの URL を含みます。URL を “Order.csp” と同じように設定することによって、そのページの最新コピーを Web サーバから要求します。

以下の文字で囲まれたコード行に注目します。

&js < ...>

このコード行は、コンテンツを JavaScript としてブラウザに送信することを Caché に指示します。

—Utils.AddShow—
Utils.AddShow
ClassMethod AddShow(ShowID As %String)
{
    // Use an existing Order object or create a new one
    If ($D(%session.Data("Order"))) {
        Set ord = %session.Data("Order")
    }
    Else {
        Set ord = ##class(TicketOrder).%New()
        Set %session.Data("Order") = ord
    }
    // Create a new TicketItem object
    Set itm = ##class(Cinema.TicketItem).%New()

    // Connect to a Show object
    Set shw = ##class(Cinema.Show).%OpenId(ShowID)
    Set itm.Show = shw
    // Connect to the Order object
    Set itm.TicketOrder = ord

    // Add the cost of this new item to the total
    Set ord.Total = ord.Total
        + (itm.AdultTickets * itm.Show.Theater.AdultPrice)
        + (itm.ChildTickets * itm.Show.Theater.ChildPrice)

    // Save incomplete order and remember its Id in %session.
    Do ord.%Save()
    Set %session.Data("Order") = ord.%Id()

    // Send javascript back to the browser, causing it to display
    //     the updated order page
    &js<parent.Order.location = "Order.csp">
    Quit
}
FeedbackOpens in a new tab