Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

Call c# server-side function using xmlhttprequest

$
0
0

I try to upload a file using xmlhttprequest.

Here is my client-side code:

function UploadFile() {

var formData = new FormData();
var file = document.getElementById("file").files[0];
formData.append("file", file);

var uploadServerSideScriptPath = "Login.aspx/test";
var xhr = new XMLHttpRequest();

xhr.open("POST", uploadServerSideScriptPath, false);
xhr.setRequestHeader("Content-Type", "multipart/form-data");
xhr.setRequestHeader("X-File-Name", file.name);
xhr.setRequestHeader("X-File-Size", file.size);
xhr.setRequestHeader("X-File-Type", file.type);


xhr.send(formData);

}



I post to 

Login.aspx/test

test function on server side is:

[WebMethod]
    public static void test(object obj)
    {
        string a = "test";
    }

but I never get to this function. I put a break point but it never being hit.

what am I doing wrong?


Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>