Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the value that is returned from the kendoui upload success or complete function

I am using Kendo UI upload control. I have defined the Kendo UI upload like this:

<input type="file" name="resume" />
$("#file").kendoUpload({
    async: {
         saveUrl: "/Home/SaveResume",             
         autoUpload: true
         },            
         complete: function (e)
         {
            // here i want to get the text that is returned from the controller
         }
});

The controller code is like:

public ActionResult SaveResume(HttpPostedFileBase resume)
{
    var text;
    // code for the file to convert to text and assign it to text
    return Json(text, JsonRequestBehavior.AllowGet);
}

After returning the code I want to retrieve the code in complete function. How can I do that?

like image 315
Pa1 Avatar asked Mar 20 '13 06:03

Pa1


2 Answers

You can get the response to success function like this

function onSuccess(e)
{
    var response = e.response.data();
}

where the return json could be

return Json(new { data = text }, "text/plain");
like image 109
Jonathan Avatar answered Nov 15 '22 21:11

Jonathan


If you just passing a string back you should be able to do:

function onSuccess(e) {
    var text = e.XMLHttpRequest.responseText;
}

You could also pass back a more complex object, if required:

// Object
public class MyObject
{
    public int ID { get; set; }
    public string Text { get; set; }
}

// Controller Action
public virtual ActionResult Upload(HttpPostedFileBase file)
{
    return this.Json(new MyObject(), "text/plain");
}

// Javascript Handler
function onSuccess(e) {
    var response = jQuery.parseJSON(e.XMLHttpRequest.responseText);
    var id = response.ID;
    var text = response.Text;
}
like image 34
Matt B Avatar answered Nov 15 '22 21:11

Matt B