SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Json get return

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Jul 2006
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Json get return

    I am trying to use C# and Jquery to look and see if a file exists. If it does, then it will download it through a File command, but if it doesn't, then I want to post a message on the screen saying that the file was not found. Everything works, except when I run a cross a file that is not there, I get an error that says:

    "This request has been blocked because sensitive information could be disclosed to third party web sites when this is used in a GET request. To allow GET requests, set JsonRequestBehavior to AllowGet."

    I tried to allow the get, but it gives me a blank page with the response text on it instead of allowing me to load it into a div tag for display on the page.

    Any ideas why it would returning as a Get instead of a POST and how i can modify it to fix the error?

    Here is my Jquery code:
    Code:
    function SoftwareDownload(FileName) {
        $('#DownloadResults').text("");
        $.ajax
        ({
            url: 'addr',
            type: 'POST',
            data: "fileName=" + FileName,
            dataType: 'json',
            success: function (response) {
                $('#DownloadResults').text(response);
            }
        }); 
    }
    and my C# code
    Code:
    public ActionResult SoftwareDownload(string fileName, DownloadModel model = null)
            {
                String downloadLocation = (Address is correct ... removing for posting resaons);
                try
                {
                    FileStream fs = System.IO.File.OpenRead(downloadLocation + "\\" + fileName);
                    return File(fs, "application/zip", fileName);
                }
                catch (Exception)
                {
                    string response = "File Not Found";
                    return Json(response);
                }
                
            }

  2. #2
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    4,826
    Mentioned
    142 Post(s)
    Tagged
    0 Thread(s)
    Be sure to congratulate xMog on earning April's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes

  3. #3
    SitePoint Zealot
    Join Date
    Jul 2006
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank You very much ... I was able to correct it


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •