0

This may seem like a nub question. I’ll be the first to admit my knowledge of JavaScript is limited, I’m very desperately trying to learn, though. I’m having a bit of trouble when attempting to pass data to an additional field.

$(function () {
    $('#upload_file').submit(function (e) {
        e.preventDefault();
        $.ajaxFileUpload({
            url: './upload/upload_file/',
            secureuri: false,
            fileElementId: 'userfile',
            dataType: 'json',
            data: {
                'title': $('#title').val()
            },
            success: function (data, status) {
                if (data.status != 'error') {
                    $('#files').html('<p>Reloading files...</p>');
                    refresh_files();
                    $('#title').val('');
                }
                alert(data.msg);
            }
        });
        return false;
    });
});   

As you can see above, I'm passing across the title value in the data parameter of the AJAX call. This is successful. The question is, how would I go about passin additional forum values within the data param?

2 Answers 2

4

Just separate the next values with commas.

data : {
        title : $('#title').val(),
        name : "hi",
        message : "I'm another param"
},
Sign up to request clarification or add additional context in comments.

1 Comment

Much appreciated. Would the original syntax vary a bit for passing values defined by a selection box?
1

An easy way to grab all form values is like this:

data: $('#my-form').serialize()

Works pretty well for me in most cases, unless I only want to grab specific values. You can read more about it here: http://api.jquery.com/serialize/

Either way, the above answer is probably what you want, I just thought I'd throw in a quick tip. I was pretty pumped when I first figured this out :)

Comments

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.