$ .getJSON返回404在firebug中找不到

时间:2011-07-07 21:07:30

标签: c# jquery asp.net ajax

这是我的$ .getJSON函数(假设要点击.ashx文件并返回一个json序列化对象,它已经测试了它):

$.getJSON($('#fileupload form').prop('action'), function (files) {
        var fu = $('#fileupload').data('fileupload');
        alert("this is the files: " + files.toString);
        fu._adjustMaxNumberOfFiles(-files.length);
        fu._renderDownload(files)
            .appendTo($('#fileupload .files'))
            .fadeIn(function () {
                // Fix for IE7 and lower:
                $(this).show();
            });
    });

编辑:

alert($('#fileupload form')。prop('action'))<返回'undefined'

不知怎的,我的js在标记之前被加载,所以它可能无法在页面上找到#fileupload。

这是完整标记:

<style type="text/css">

    @import url('http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/themes/base/jquery-ui.css');
    @import url('/_layouts/IrvineCompany.SharePoint.CLM/css/jquery.fileupload-ui.css');
    @import url('/_layouts/IrvineCompany.SharePoint.CLM/css/style.css');
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/jquery-ui.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js"></script>    

<script type="text/javascript" src="/_layouts/IrvineCompany.SharePoint.CLM/js/UploadFile/jquery.iframe-transport.js"></script>
<script type="text/javascript" src="/_layouts/IrvineCompany.SharePoint.CLM/js/UploadFile/jquery.fileupload.js"></script>
<script type="text/javascript" src="/_layouts/IrvineCompany.SharePoint.CLM/js/UploadFile/jquery.fileupload-ui.js"></script>
<script type="text/javascript" src="/_layouts/IrvineCompany.SharePoint.CLM/js/UploadFile/application.js"></script>
<div id="fileupload">
    <form action="/_layouts/IrvineCompany.SharePoint.CLM/aspx/Upload.ashx" method="post" enctype="multipart/form-data">
        <div class="fileupload-buttonbar">
            <label class="fileinput-button">
                <span>Add files...</span>
                <input type="file" name="files[]" multiple="multiple" />
            </label>
       <%-- <button type="submit" class="start">Start upload</button>
            <button type="reset" class="cancel">Cancel upload</button> --%>
            <button type="button" class="delete">Delete all files</button>
            <div class="fileupload-progressbar"></div>
        </div>
    </form>
    <div class="fileupload-content">
        <table class="files"></table>
    </div>
</div>
<script id="template-upload" type="text/x-jquery-tmpl">
    <tr class="template-upload{{if error}} ui-state-error{{/if}}">
        <td class="preview"></td>
        <td class="name">${name}</td>
        <td class="size">${sizef}</td>
        {{if error}}
            <td class="error" colspan="2">Error:
                {{if error === 'maxFileSize'}}File is too big
                {{else error === 'minFileSize'}}File is too small
                {{else error === 'acceptFileTypes'}}Filetype not allowed
                {{else error === 'maxNumberOfFiles'}}Max number of files exceeded
                {{else}}${error}
                {{/if}}
            </td>
        {{else}}
            <td class="progress"><div></div></td>
            <td class="start"><button>Start</button></td>
        {{/if}}
        <td class="cancel"><button>Cancel</button></td>
    </tr>
</script>
<script id="template-download" type="text/x-jquery-tmpl">
    <tr class="template-download{{if error}} ui-state-error{{/if}}">
        {{if error}}
            <td></td>
            <td class="name">${name}</td>
            <td class="size">${sizef}</td>
            <td class="error" colspan="2">Error:
                {{if error === 1}}File exceeds upload_max_filesize (php.ini directive)
                {{else error === 2}}File exceeds MAX_FILE_SIZE (HTML form directive)
                {{else error === 3}}File was only partially uploaded
                {{else error === 4}}No File was uploaded
                {{else error === 5}}Missing a temporary folder
                {{else error === 6}}Failed to write file to disk
                {{else error === 7}}File upload stopped by extension
                {{else error === 'maxFileSize'}}File is too big
                {{else error === 'minFileSize'}}File is too small
                {{else error === 'acceptFileTypes'}}Filetype not allowed
                {{else error === 'maxNumberOfFiles'}}Max number of files exceeded
                {{else error === 'uploadedBytes'}}Uploaded bytes exceed file size
                {{else error === 'emptyResult'}}Empty file upload result
                {{else}}${error}
                {{/if}}
            </td>
        {{else}}
            <td class="preview">
                {{if thumbnail_url}}
                    <a href="${url}" target="_blank"><img src="${thumbnail_url}"></a>
                {{/if}}
            </td>
            <td class="name">
                <a href="${url}"{{if thumbnail_url}} target="_blank"{{/if}}>${name}</a>
            </td>
            <td class="size">${sizef}</td>
            <td colspan="2"></td>
        {{/if}}
        <td class="delete">
            <button data-type="${delete_type}" data-url="${delete_url}">Delete</button>
        </td>
    </tr>
</script>

编辑:

检查了我的标记,由于某些原因我在那里有我的表单标签,但是当我检查网站的实际标记时它就消失了。

3 个答案:

答案 0 :(得分:1)

尝试使用.attr代替.prop

$('#fileupload form').attr('action')

答案 1 :(得分:0)

$.getJSON($('#fileupload form').attr("action"), function (files) {
        var fu = $('#fileupload').data('fileupload');
        alert("this is the files: " + files.toString);
        fu._adjustMaxNumberOfFiles(-files.length);
        fu._renderDownload(files)
            .appendTo($('#fileupload .files'))
            .fadeIn(function () {
                // Fix for IE7 and lower:
                $(this).show();
            });
    });

答案 2 :(得分:0)

确保将您的javascript代码包装在$(function(){..your code here..})

如果您这样做,则在尝试提醒时应该得到正确的结果:http://jsfiddle.net/maniator/3MQ8W/

看到有两个警报,第一个是undefined