[英]invoke and pass data from c# code behind to Javascript
Hi I have a ASPX page like this: 嗨,我有一个像这样的ASPX页面:
<head>
<title>Sample</title>
<script src="/javascript/jquery-1.11.1.js"></script>
<script src="/javascript/angular.js"></script>
<script src="/javascript/jquery-ui.js"></script>
<script type="text/javascript">
function myFunction(message) {
var stock = new Object();
stock.symbol = message;
$.ajax({
url: '/experiments/Week11/Buy_Experiment1.aspx/BuyStock',
data: stock,
error: function () {
$('#info').html('<p>An error has occurred</p>');
},
dataType: 'json',
success: function (data) {
console.log(data);
},
type: 'POST'
});
}
</script>
</head>
And this is my code behind, 这是我的代码背后,
public partial class sample : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(this, GetType(), "YHOO", "myFunction();", true);
}
}
I am able to successfully call the JQUERY from code behind, but my concern is to send the data "YHOO" from the C# code-ScriptManager to the myFunction javascript variable "message" such that i can send the data "message" as a post data to my backend Web services. 我能够从后面的代码成功调用JQUERY,但我的担心是将数据“ YHOO”从C#代码-ScriptManager发送到myFunction javascript变量“ message”,这样我就可以将数据“ message”作为帖子发送数据发送到后端Web服务。 Please help !!!!!!
请帮忙 !!!!!!
Try this: 尝试这个:
public partial class sample : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(this, GetType(), "YHOO", "myFunction('YHOO');", true);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.