Reputation: 10805
I am forming some java script code like this
var url = '<%= Server.MapPath(".") %>' + '/Variablesvariable.txt';
alert(url);
xmlhttp.open("GET", url , true); // url +'/Variables/variable.txt'
xmlhttp.send();
//alert('<%= Server.MapPath(".") %> \Variablesvariable.txt')
whats wrong with this?
the URL don't pass to method proper, at open method it get crashes, so am i forming the wrong URL, or some other way exist in the java script to concatenate it?
I see URL in add watch
it is forming like this
" url\"D:VisualStudio2010ProjectsWebSitesTinyEditor/Variablesvariable.txt\""
whats wrong?
Upvotes: 0
Views: 275
Reputation: 16613
<%= Server.MapPath(".") %>
This generates a physical path like c:somefolder
. What you need to pass in is a url which is available on the web so something like /myfolder/Variablesvariable.txt.
So make it up like:
var url = '/myfolder/variables.txt';
alert(url);
Where you place the file variables.txt into a subfolder myfolder of your web application.
If you want to have it more dynamic you can do like this in your codebehind:
protected void Page_Load(object sender, EventArgs e)
{
VariableUrl = ResolveUrl("~/Scripts/variables.txt");
}
public String VariableUrl { get; set; }
and in the markup:
var url = '<%= VariableUrl %>';
alert(url);
So what you put as parameter into the ResolveUrl method is entirely up to you.
Upvotes: 1