[英]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"]);
}
}
}
When i test in test.htm 当我在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>
and , response dont display in test.htm 和,响应不会显示在test.htm中
SO: Pass vars to JavaScript via the SRC attribute SO: 通过SRC属性将vars传递给JavaScript
*Edit : Updated to accomodate your comment. *编辑 :已更新以容纳您的评论。
If you'd like to display anything returned by a server side-script/page, you'd need to use AJAX. 如果要显示服务器端脚本/页面返回的任何内容,则需要使用AJAX。 I would recommend using jQuery for that purpose.
我建议为此使用jQuery 。 A simple example of using it after you've included it looks like this:
包含它后使用它的一个简单示例如下所示:
$.get("mypage.aspx", function(data){
alert("Data Loaded: " + data);
});
Once you call this on your page, an alert dialogue box will appear with the output of your page contained in "data". 在页面上调用此按钮后,将出现一个警告对话框,页面输出包含在“数据”中。 Go through jQuery's tutorial section .
浏览jQuery的教程部分 。 Learn it, live it, love it!
学习,生活,热爱它! :)
:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.