ASP.net Uploadify Querystring checkbox value

笑着哭i 提交于 2020-01-06 15:59:10

问题


I am using Uploadify with ASP.Net 4.0 and a Generic Handler for the backend. now I could use the scriptData part of Uploadify If I only knew how to read the JSon that is being posted to the Generic Handler so instead I opted for just sending the needed data through querystring which I have tested by hardcoding the query string and it works but when I try to get the value of a checkbox using the val() option it just passes the value of "on" no matter if the check box is or is not checked. I have also tried simply using $('#mainimg').is(':checked') which does not give me anything.

            $('#file_upload').uploadify({

            'uploader': '/uploadify/uploadify.swf',
            'script': '/services/Upload.ashx?ismain=' + $('#mainimg').val(), <--- HERE IS THE PROBLEM
            'multi': false,
            'fileExt': '*.jpg;*.gif;*.png',
            'sizeLimit': 10000000,
            'scriptAccess': 'sameDomain',
            'cancelImg': '/uploadify/cancel.png',
            'onAllComplete': function (event, data) {
                alert(data.filesUploaded + ' files uploaded successfully!');
            },
            'onCancel': function (event, ID, fileObj, data) {
                alert('The upload of ' + fileObj.name + ' has been canceled!');
            },
            'onError': function (event, ID, fileObj, errorObj) {
                alert(errorObj.type + ' Error: ' + errorObj.info);
            },
            'onSelectOnce': function (event, data) {
                alert(data.filesSelected + ' files were selected for upload.');
            },
            'auto': true

        });

I've set the value of the checkbox using this

$('#mainimg').click(function () {

                        if ($('#mainimg').is(':checked')) {
                            $('#mainimg').val('true');
                        }
                        else { $('#mainimg').val('false'); }
                        alert($('#mainimg').val());
                    });

I have even tried setting a variable using this code

$('#mainimg').click(function () {

                        if ($('#mainimg').is(':checked')) {
                            checkboxStatus = false; ;
                        }
                        else { checkboxStatus = true; }
                        alert(checkboxStatus);
                    });

But even though I would test it with an alert and it shows the right data in the alert when it goes to the uploadify script it just provides the value of 'false'

can anyone see what it is that I am doing wrong here?


回答1:


You are right that the value for the checkbox is always "on", so you have to send something else if the checkbox is checked, i.e. the text of the checkbox, or its label's value.

(...)'script': '/services/Upload.ashx?ismain=' + $('#mainimg').is(':checked')?'true':'false',


来源:https://stackoverflow.com/questions/9354598/asp-net-uploadify-querystring-checkbox-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!