ajax调用错误"未捕获TypeError:无法读取属性' status' of null"

时间:2014-09-10 06:01:22

标签: ajax codeigniter

当我点击上传cv浏览按钮时,它应该调用$('#upload_resume_doc')。change(function()函数,但它在控制台中显示错误,现在没有调用ajax调用。我必须面对这个所有浏览器都存在问题。

<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.1/jquery-ui.js"></script>
<script src="<?php echo base_url("resources/js`enter code here`/jquery.bonsai.js"); ?>"></script>
<div id="content-wrapper" class="container">
    <div class="advance-search-panel">
        <div class="panel-group" id="accordion">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <a data-toggle="collapse" data-parent="#accordion" href="#by_cv_matches">
                        <div class="media">
                            <div class="pull-left"> <img class="media-object" src="<?php echo base_url("resources/images/search-image-cv.jpg"); ?>"  alt=""> </div>
                            <div class="media-body">
                                <h3 class="media-heading">Search Jobs with CV Matches</h3>
                                Match Jobs Using Skills in Your CV. </div>
                        </div>
                    </a> 
                </div>

                <div id="by_cv_matches" class="panel-collapse">
                    <div class="panel-body">
                        <form class="form-inline" action="<?php echo base_url('job/search'); ?>" method="post" role="form" enctype="multipart/form-data">
                            <div class="form-group col-lg-8">
                                <!-- Display filename inside the button instead of its label -->
                                <input id="upload_resume_doc" name="document" type="file" class="input-lg col-lg-12 text-left" data-filename-placement="inside" title="Upload CV - Browse">
                                <div id="loading"></div>
                                <div id="ext_keywords" style=" margin-top: 50px;"><lable><h4>Extracted keywords from your CV</h4></lable>
                                    Here are extracted keywords from your CV, <br>You can add or remove keywords from extracted keywords.
                                <textarea  type="text" id="keywords" name="keywords" onkeynpress="getJobId(id);" value="" placeholder="Enter the Message" rows="6" cols="65"/></textarea>
                                <div class="form-group">
                                        <select name="jobIndustry" class="form-control input-lg" style="width:300px">
                                    <option value="">Select Industry</option>
                                    <?php foreach ($job_industries as $job) { ?>
                                        <optgroup label="<?php echo ucwords($job->name) ?>">
                                            <?php if (!empty($job->subcategories)) { ?>
                                                <?php foreach ($job->subcategories as $sub) { ?>
                                                    <option value="<?php echo $sub->id; ?>"><?php echo ucwords($sub->name) ?></option>
                                                <?php } ?>
                                            <?php } ?>
                                        </optgroup>
                                    <?php } ?>
                                </select>
                            </div>

                                <div class="form-group" class="input-lg col-lg-12 text-left" style="width: 500px;">
                                        <!--<input type="text" class="form-control input-lg" id="main_search_minimumSalary" placeholder="Minimum Salary" name="minimumSalary">  -->

                                            <label>Job Type</label><br>
                                            <select name="jobtype" id="jobtype"  style="width: 265px; height: 35px;" onchange="showHideSalaryType();">
                                                <option value="">Select Job Type</option>
                                                <option value="Permanent" <?php echo set_select('jobtype', 'Permanent'); ?> >Permanent</option>
                                                <option value="Part-Time" <?php echo set_select('jobtype', 'Part-Time'); ?> >Part-Time</option>
                                                <option value="Contract" <?php echo set_select('jobtype', 'Contract'); ?> >Contract</option>
                                            </select>
                                        </div>

                                    <div class="col-lg-12" id="parmanent">
                                        <h4 class="text-blue" >PER ANNUM</h4>
                                        <div class="form-group">
                                            <div class="form-inline">
                                                <label>From</label>
                                                <input href="javascript:void(0)" type="text" name="min_salary" value="<?php echo set_value('min_salary'); ?>" placeholder="Minimum Salary" class="form-control input-lg" style="width: 210px;">
                                                <label style="margin-left: 20px;">to </label>
                                                <input href="javascript:void(0)" type="text" name="max_salary" value="<?php echo set_value('max_salary'); ?>" placeholder="Maximum Salary" class="form-control input-lg" style="width: 230px; margin-left: 30px;">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-lg-12" id="perday" style="display: none;">
                                        <h4 class="text-blue">PER DAY SALARY</h4>
                                        <div class="form-group">
                                            <div class="form-inline">
                                                <label>From</label>
                                                <input href="javascript:void(0)" type="text" name="min_salary_day" value="<?php echo set_value('min_salary_day'); ?>" placeholder="Minimum Salary" class="form-control input-lg" style="width: 210px;">
                                                <label style="margin-left: 20px;">to </label>
                                                <input href="javascript:void(0)" type="text" name="max_salary_day" value="<?php echo set_value('max_salary_day'); ?>" placeholder="Maximum Salary" class="form-control input-lg" style="width: 230px; margin-left: 30px;">
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-lg-12" id="perhour" style="display: none;">
                                        <h4 class="text-blue">PER HOUR SALARY</h4>
                                        <div class="form-group">
                                            <div class="form-inline">
                                                <label>From</label>
                                                <input href="javascript:void(0)" type="text" name="min_salary_hour" value="<?php echo set_value('min_salary_hour'); ?>" placeholder="Minimum Salary" class="form-control input-lg" style="width: 210px;">
                                                <label style="margin-left: 20px;">to </label>
                                                <input href="javascript:void(0)" type="text" name="max_salary_hour" value="<?php echo set_value('max_salary_hour'); ?>" placeholder="Maximum Salary" class="form-control input-lg" style="width: 230px; margin-left: 30px;">
                                            </div>
                                        </div>
                                    </div>
                                </div>
</div>

                            <button type="submit" id="search" class="btn btn-lg btn-yellow"><span class="glyphicons glyphicons-search"></span> SEARCH</button>
                        </form>
                    </div>
                </div>
            </div>
            <div class="panel panel-default">
                <div class="panel-heading">
                    <a data-toggle="collapse" data-parent="#accordion" href="#by_Industry_Sector">
                        <div class="media">
                            <div class="pull-left"> <img class="media-object" src="<?php echo base_url("resources/images/industry-sector.jpg"); ?>"  alt=""> </div>
                            <div class="media-body">
                                <h3 class="media-heading">Search Jobs by Industry Sector</h3>
                                Search Job in a Particular Industry Sector or Sub Sector </div>
                        </div>
                    </a> 
                </div>
                <div id="by_Industry_Sector" class="panel-collapse collapse">
                    <div class="panel-body">
                        <form class="form-inline" role="form" method="post" action="<?php echo base_url('job/search');?>">
                            <div class="form-group">
                                <select name="jobIndustry" class="form-control input-lg" style="width:500px">
                                    <option value="">Select Industry</option>
                                    <?php foreach ($job_industries as $job) { ?>
                                        <optgroup label="<?php echo ucwords($job->name) ?>">
                                            <?php if (!empty($job->subcategories)) { ?>
                                                <?php foreach ($job->subcategories as $sub) { ?>
                                                    <option value="<?php echo $sub->id; ?>"><?php echo ucwords($sub->name) ?></option>
                                                <?php } ?>
                                            <?php } ?>
                                        </optgroup>
                                    <?php } ?>
                                </select>

                            </div>
                            <button type="submit" class="btn btn-lg btn-yellow"><span class="glyphicons glyphicons-search"></span> SEARCH</button>
                        </form>
                    </div>
                </div>
            </div>
            <div class="panel panel-default">
                <div class="panel-heading">
                    <a data-toggle="collapse" data-parent="#accordion" href="#by_Location">
                        <div class="media">
                            <div class="pull-left"> <img class="media-object" src="<?php echo base_url("resources/images/search-by-location.jpg"); ?>"  alt=""> </div>
                            <div class="media-body">
                                <h3 class="media-heading">Search Jobs by Location</h3>
                                Find All Jobs Within an area in UK </div>
                        </div>
                    </a> 
                </div>




                <div id="by_Location" class="panel-collapse collapse">
                    <div class="panel-body">
                        <form class="form-inline" role="form"  method="post" action="<?php echo base_url('job/search');?>">
                            <div class="form-group">
                                <input type="text" name="area" class="form-control input-lg" id="area"  style="width:500px" placeholder="LOCATION">
                            </div>
                            <button type="submit" class="btn btn-lg btn-yellow"><span class="glyphicons glyphicons-search"></span> SEARCH</button>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!--<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script> 
<script src="http://malsup.github.com/jquery.form.js"></script> 
<script src="<?php echo base_url("resources/js/file.uploader.js"); ?>"></script>-->

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script> 
<script src="http://malsup.github.com/jquery.form.js"></script> 
<script src="<?php echo base_url("resources/js/file.uploader.js"); ?>"></script>
<!--<script>
    //    $(document).ready(function() {
    $("#upload_resume_doc").change(function() {

        ajaxFileUploader("#upload_resume_doc", {
            alert('sssssss');
            url: base_url + 'uploader/upload_and_search_keywords',
            loader: '#uploadProcess2',
            data: {
                doc_name: $("#document_name_id").val()
            },
            success: function(response) {
                console.log(response);
                if (response.status === 200) {
                    var ext = response.data.ext;
                    var icon;
                    if (ext == '.doc' || ext == '.docx') {
                        icon = 'doc-icon.png';
                    } else if (ext == '.xls' || ext == '.xlsx') {
                        icon = 'excel-icon.png';
                    } else if (ext == '.pdf') {
                        icon = 'pdf-icon.png';
                    }
                    if (response.keywords == "" || response.keywords == ",") {
                        displayUIMessage(response.message);
                    } else {
                        $('#main_search_Keyword').val(response.keywords);
                        $('#mainSubmitButton').click();
                    }
                   $('#AuctionDocumentsList').append(imgHtml);


                } else {
                    displayUIMessage(response.message);
                }
                $("#document_name_id").val('');
            }
        });
    });
    //    });

</script>-->
<script type="text/javascript">
    //    $(document).ready(function() {
    $("#upload_resume_doc").change(function() {

        ajaxFileUploader("#upload_resume_doc", {

            url: base_url + 'uploader/upload_and_search_keywords',
//             alert('adsfasfas');
            loader: '#uploadProcess2',
            data: {
                doc_name: $("#document_name_id").val()
            },
            success: function(response) {

                console.log(response);
                if (response.status === 200) {
                    var ext = response.data.ext;
                    var icon;
                    if (ext == '.doc' || ext == '.docx') {
                        icon = 'doc-icon.png';
                    } else if (ext == '.xls' || ext == '.xlsx') {
                        icon = 'excel-icon.png';
                    } else if (ext == '.pdf') {
                        icon = 'pdf-icon.png';
                    }
                    if (response.keywords == "" || response.keywords == ",") {
                        displayUIMessage(response.message);

                } else {
                    displayUIMessage(response.message);
                }
                $("#document_name_id").val('');
            }
        });
    });


</script>
 <script>

    $('#upload_resume_doc').change(function () {
    // add loading image to div
    $('#loading').html('<img `enter code here`src="http://preloaders.net/preloaders/287/Filling%20broken%20ring.gif"> loading...');
    // run ajax request
    $.ajax({
        type: "GET",`enter code here`
        dataType: "json",
        url: "https://api.github.com/users/jveldboom",
        success: function () {
//            console.log(msg) 
            // replace div's content with returned data
            // $('#loading').html('<img src="'+d.avatar_url+'"><br>'+d.login);
            // setTimeout added to show loading
            setTimeout(function () {
//                $('#loading').html('<img src="' +  + '"><br>' + d.login);
            }, 2000);
        }
    });
});
            </script>

            <script>
    function showHideSalaryType() {
        var dropDownValue = document.getElementsByName('jobtype'); //will be an array
        var result = dropDownValue[0].options[dropDownValue[0].selectedIndex].value;
        if (result === 'Part-Time' || result === 'Contract') {
            $("#parmanent").hide();
            $("#perday").show();
            $("#perhour").show();
        } else {
            $("#parmanent").show();
            $("#perday").hide();
            $("#perhour").hide();
        }
    }

</script>`enter code here`

1 个答案:

答案 0 :(得分:0)

您需要返回并阅读jQuery文档。响应,传递给您成功的第一个参数是来自服务器的文本响应(或转换为其他形式,如json)。 SECOND参数是textstatus。第三个参数是jqXHR请求。

你的第一个参数永远不会有#34;状态&#34;除非你正在让你回归的那部分,我怀疑。

其次,$ .ajax成功仅在状态为200时被调用,因此您的检查毫无意义。

但是因为我没有看到&#34; ajaxfileuploader&#34;的代码。以上可能无关紧要