c# Calling Server side method using JQuery
<p>Im trying to call a server method in my aspx.cs to delete all the files in a directory when a user closes the browser.</p>

<pre><code>[WebMethod]
    public static void fileDelete()
    {

        string[] uploadedFiles = Directory.GetFiles(@"C:\Users\Lambo\Documents\Visual Studio 2010\Projects\test\test\testPdfIn");
        foreach (string uploaded in uploadedFiles)
        {
            File.Delete(uploaded);
        }
    }
</code></pre>

<p>======================================================================</p>

<p>EDIT</p>

<p>I've tried the POST method but it still doesn't seem to work. I've changed the URL too.</p>

<p>Over at the client side im using this:</p>

<pre><code>    $(function () {
        $(window).unload(function () {
            alert("Files have been deleted")
             jQuery.ajax({ type: 'POST', url: "http://localhost:19642/success.aspx/fileDelete", async: true });
        });
    });
</code></pre>

<p>However it doesnt seem to be working. Are the codes wrong in someway?</p>
