0

I am using ajaxFileUpload jQuery plugin to upload an image to ASP.NET server.

I was able to upload an image successfully, but I also want to pass data to the server as well. I wasn't able to do so. When I try to pass a JSON data I get the following error in the browser's console:

jQuery.handleError is not a function

The Javascript code:

 $.ajaxFileUpload
(
    {
        url: 'http://localhost:23999/administration.asmx/UploadedFile',
        secureuri: false,
        fileElementId: 'ImageUpload',
        dataType: 'json',
        data: "test",
        success: function (data, status) {
            if (typeof (data.error) != 'undefined') {
                if (data.error != '') {
                    alert(data.error);
                } else {
                    alert(data.msg);
                }
            }
        },
        error: function (data, status, e) {
            alert(e);
        }
    }
)

WebService C#:

[WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public string UploadedFile()
    {
        var a = HttpContext.Current.Request;
        HttpPostedFile file = HttpContext.Current.Request.Files[0];

        byte[] buffer;
        Stream fileStream = file.InputStream;
        ............

How can I pass JSON data to the server? Thanks.

1 Answer 1

1

On this link : http://www.jchilders.com/AjaxFileUpload/demo/ it says there's an option you could use to pass data :

additionalData : Additional data you would like to pass along with the request.

You can try to send the data this way :

var data = { "varId" : varValue };

Sign up to request clarification or add additional context in comments.

6 Comments

It's a different script, and the links to the source don't work
thanks. Without the "data" option, your code works, right ? Could you show the ajaxfileupload.js code as well please ? can't find it with the link you gave.
Yes it works without it. When I pass the data value, I can see that it read it inside the plugin, but something goes wrong from that point on, something that I can't figure out.
It works now with the data for some reason :) -- do you know how can I access it in .NET?
I need more info to help you. Could you show the plugin code ? And the code you use on the server side ? When you say " I can see that it read it inside the plugin", where exactly do you read it ?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.