SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Oct 2007
    Location
    East Sussex
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    YUI dialog upload file problem

    Hi,

    Im really hoping someone can help here - what im trying to do is have a form upload a file using AJAX with the YUI Dialog widget. The form is submited to an asp.net MVC application and all seems to work fine until the Json string is returned - IE7 then pops up a security warning box instead of processing the returned json encoded string. My js code is;

    Code:
    var dialog = new YAHOO.widget.Dialog("newFile",
    							{
    							    width: "30em",
    							    fixedcenter: true,
    							    visible: true,
    							    constraintoviewport: true,
    							    modal: true,
    							    buttons: [{ text: "Submit", handler: PopupSubmit, isDefault: true },
    								          { text: "Cancel", handler: PopupClose}]
    							});
    
        dialog.setBody('<form id="uploadFile" enctype="multipart/form-data" method="post" action="/File/Upload">' +
    			                '<label for="uploadedFile">File:</label> <input type="file" id="uploadedFile" name="uploadedFile" />' +
    			                '<input type="hidden" name="assignToId" value="123" />' +
    		                    '</form>')
        dialog.setHeader("Add a new File");
    
        dialog.callback.upload = processNewFile;
        dialog.render(document.body);

  2. #2
    SitePoint Enthusiast Dharma's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What's the warning IE7 gives you?

  3. #3
    SitePoint Member
    Join Date
    Oct 2007
    Location
    East Sussex
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    File Downlad - Security Warning

    Do you want to save this file, or find a program onine to open it?
    Name: 335d4fe3
    Type: Unknown File Type

    I also get this warning with Firefox

  4. #4
    SitePoint Member
    Join Date
    Oct 2007
    Location
    East Sussex
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok so it's been a while but today I went back to the problem and sorted it.

    The problem is that if you use (as i did) the method Json(object data) in the base MVC Controller class it will return a json encoded string with the content type set to "application/json" - which is fine except that if you upload a file the browser expects you to return HTML.

    All I've done to fix this is use the overloaded method Json(object data, string contentType), and set its value to something like;

    Json(myData, "text/html");

    and its fixed the problem.
    Maybe this will help someone else too.


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
  •