Ajax Post方法为空

时间:2015-03-01 10:04:25

标签: php jquery ajax codeigniter post

我正在使用jquery ajax并且代码工作正常,直到新服务器移动到新服务器上并且在某种程度上新服务器ajax post方法没有通过POST方法传递任何数据,也没有给出任何响应。我正在使用codeigniter框架。

这是我的代码段:

$(document).ready(function()
{
    //alert(progressbar.width);
    //alert($('.upload-statusbar').width());
    var c =0;
    var settings = {
    url: "class_name/function_name",
    method: "POST",
    //allowedTypes:"jpg,png,gif,doc,pdf,zip",
    allowedTypes:"jpg,png,gif",
    fileName: "userfile[]",
    multiple: true,
/*  onbeforeSend:function()
    {
        $('#submitBtn').prop('disabled','true');
        alert('upload starts');
    },*/
    onSelect:function()
    {
        //alert("Wait untill image being uploaded !!");
        $('#submitBtn').attr('disabled','true');
        $('#submitBtn').addClass('disabled-button');
        $('.disabled-div').css('display','block');
    },
    onSuccess:function(files,data,xhr)
    {
        //alert(data);
        c++;
        //alert(c);
        var x = data;
        image = "http://domain.com/folder_name/"+data;
        //alert(x);
        var use_class = data.substr(0, data.lastIndexOf('.'));
        //alert(use_class);
        $("#status").html("<font color='green'>Upload is 100%</font>");
    },
    afterUploadAll:function()
    {
        alert('all images uploaded');   
    },
    onError: function(files,status,errMsg)
    {       
        $("#status").html("<font color='red'>Upload is Failed</font>");
    }
}
$("#mulitplefileuploader").uploadFile(settings);
});

由于

1 个答案:

答案 0 :(得分:0)

尝试在ajax url部分传递完整的url ... 喜欢

url:&#34; http://domain.com/class_name/function_name&#34;

或尝试以下代码进行ajax图片上传...

var url = BASE_URL + 'class_name/function_name';

    var xhr = new XMLHttpRequest();
    xhr.open('POST', url);
    $('#image').attr('src', BASE_URL + "artefacts/images/site/loading.gif");


    xhr.upload.onprogress = function(e) {
        /*
         * values that indicate the progression
         * e.loaded
         * e.total
         */

        $('#image').attr('src', BASE_URL + "images/loading.gif");

        $('#image').show();
    };
    xhr.onload = function() {
        if (xhr.readyState === 4 && (xhr.status === 200 || xhr.status === 0)) {
            // if your server sends a message on upload sucess,
            // get it with xhr.responseText
            //alert(xhr.responseText);

            var responseData = eval('(' + xhr.responseText + ')');

            var dimension = String(width) + 'x' + String(height);

            $('#image).hide();

            // Display error messages on view page starts - 10/12/2014
            if (responseData.error !== null)
            {
                $('#image').attr('src', BASE_URL + "images/Pic.png");

                $('#image').show();
                $('.showMsg').html(responseData.error[0]);
            }

            // Check if image has been uploaded successfully
            if (responseData.success !== null) {

                $('#image').attr('src', BASE_URL + 'images/' + responseData.success[dimension] + '?' + new Date().getTime());

                $('#image').show();

                $('#uploaded_image').val(responseData.success[dimension]);

            }
        }
    };
    // upload success
    var form = new FormData();
    form.append('title', file.files[0].name);
    form.append('profile_photo', file.files[0]);

    xhr.send(form);

忽略与您无关的代码行...