I am trying to hide the result of a C# method which is called from my javascript code in my aspx file. When I view the page source I want to return value, presently 'HI_MOM!', to not be visible.
My ASPX:
<html>
<head>
<title>Hide Me</title>
</head>
<body><div id="center"><div id="fig">
<script type="text/javascript">
var url = <%="'"+magic()+"'"%>;
document.write(url);
</script>
</div></div></body>
</html>
My C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class TestTest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public string magic()
{
return "HI_MOM!";
}
}
Source Code after Running:
<html>
<head>
<title>Hide Me</title>
</head>
<body><div id="center"><div id="fig">
<script type="text/javascript">
var url = HI_MOM!;
document.write(url.toString);
</script>
</div></div></body>
</html>
Basically, I want to make it so that when I view the source code for the page the line "var url = HI_MOM!;" is not visible to the user or is masked in some way.
EDIT:
ANSWER: (with thanks to @Shadow Wizard for pointing me in the right direction)
In TestTest.aspx:
<script type="text/javascript" src="./jquery.js"></script>
. . .
jQuery.ajax({
type: 'POST',
url: 'TestTest.aspx/magic',
cache: false,
data: '{}',
contentType: 'application/json; charset=utf-8',
dataType: 'text',
success: function (msg) {
var result = eval('(' + msg + ')');
result = eval('('+result["d"]+')');
//do something with your string =]
}
});
In TestTest.aspx.cs:
[WebMethod]
public static string magic()
{
return "HI_MOM!";
}