I have written such a code in javascript i want to upload file to server, but i cant write code on server side, i dont know where should i write? Should i write in Page_Load event??? can u help me pls?
function XHR() {
var xhr = new XMLHttpRequest();
var file = document.getElementById("File1").files.item(0);
xhr.open('POST','HaberEkle.aspx', true);
xhr.setRequestHeader("Content-type", file.type);
xhr.setRequestHeader("X_FILE_NAME", file.name);
xhr.send(file);
}
In your code-behind for HaberEkle.aspx, you can implement the processing in the Page_Load method. Within that method, you may obtain any POST data using Request.Form["key"] and any GET data using Request.QueryString["key"]. To make HaberEkle.aspx more
like a webservice, you can leave it completely blank (except for the page directive) and output messages (recommend JSON or XML format) in the code-behind using Response.Write(). Then your javascript will have some server response data to parse. This is
kind of a hacky method of implementing webservices as .NET has a more integrated implementation for you to use, but I've implemented webservices this way before.
As for whether or not this is going to work for an "AJAX Upload", I can't be of much help to you there. I'm still operating under the understanding that this can't be done this way for security reasons. I'd be happy to be wrong about this.
"Dream as if you'll live forever, live as if you'll die today." --James Dean
None
0 Points
1 Post
How to handle XMLHTTPrequest request in aspx page
Jun 20, 2012 01:09 PM|netman38|LINK
Hi,
I have written such a code in javascript i want to upload file to server, but i cant write code on server side, i dont know where should i write? Should i write in Page_Load event??? can u help me pls?
function XHR() {
var xhr = new XMLHttpRequest();
var file = document.getElementById("File1").files.item(0);
xhr.open('POST','HaberEkle.aspx', true);
xhr.setRequestHeader("Content-type", file.type);
xhr.setRequestHeader("X_FILE_NAME", file.name);
xhr.send(file);
}
Star
9496 Points
2514 Posts
Re: How to handle XMLHTTPrequest request in aspx page
Jun 20, 2012 06:13 PM|AceCorban|LINK
In your code-behind for HaberEkle.aspx, you can implement the processing in the Page_Load method. Within that method, you may obtain any POST data using Request.Form["key"] and any GET data using Request.QueryString["key"]. To make HaberEkle.aspx more like a webservice, you can leave it completely blank (except for the page directive) and output messages (recommend JSON or XML format) in the code-behind using Response.Write(). Then your javascript will have some server response data to parse. This is kind of a hacky method of implementing webservices as .NET has a more integrated implementation for you to use, but I've implemented webservices this way before.
As for whether or not this is going to work for an "AJAX Upload", I can't be of much help to you there. I'm still operating under the understanding that this can't be done this way for security reasons. I'd be happy to be wrong about this.
Star
14065 Points
3270 Posts
Re: How to handle XMLHTTPrequest request in aspx page
Jun 20, 2012 11:42 PM|roopeshreddy|LINK
Hi,
Consider AysncFileUpload from AJAX ToolKit
http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/AsyncFileUpload/AsyncFileUpload.aspx
Regrading your question, check the forum thread!
http://forums.asp.net/t/1623460.aspx/1
They discussed regrading jQuery File Upload, which is similar to AJAX file upload!
Hope it helps u...
Roopesh Reddy C
Roopesh's Space