簡體   English   中英

如何顯示來自javascript響應的文本

[英]how to display text from response from javascript

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page 
{
    NurseCounter nc;
    protected void Page_Load(object sender, EventArgs e)
    {
        int id = int.Parse(Request.QueryString["counterid"]);
        int play = int.Parse(Request.QueryString["display"]);
        try
        {
            nc = new NurseCounter(id);
            Response.Write(nc.RenterCounter(play));
        }
        catch
        {
            Response.Write("Counter Error Id=" + Request.QueryString["counterid"]);
        }
    }
}

當我在test.htm中測試時


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Untitled Page</title>
</head>
<body>
<script type="text/javascript" src="http://localhost:4464/NurseCounter/Default.aspx?counterid=2&display=6"></script>
</body>
</html>

和,響應不會顯示在test.htm中

SO: 通過SRC屬性將vars傳遞給JavaScript

*編輯 :已更新以容納您的評論。

如果要顯示服務器端腳本/頁面返回的任何內容,則需要使用AJAX。 我建議為此使用jQuery 包含它后使用它的一個簡單示例如下所示:

$.get("mypage.aspx", function(data){
  alert("Data Loaded: " + data);
});

在頁面上調用此按鈕后,將出現一個警告對話框,頁面輸出包含在“數據”中。 瀏覽jQuery的教程部分 學習,生活,熱愛它! :)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM