Nie Selam Nie Selam - 4 months ago 20
Ajax Question

CORS Ajax POST variables empty in live server but work in local server

After days (and a bit of spamming here and there), I did get CORS to work for my CodeIgniter applications. However, POST variables are empty in the PHP side in live server. the whole $_POST array is empty for some reason. Here is my ajax code:

var postForm = {'e':'sammy'}; //data to process
$.ajax({
type: "POST",
url: "http://www.abc.ca/types/add",

data: postForm,
dataType : "json",

cache: "false",
contentType: "application/json",
success: function (result) {

//result here is blank
alert(result);
},
fail: function (result){
alert(result);
}


});


and the called php function (without the whole controller class):

function add() {
//Add new a biz type
file_put_contents('trial.txt',implode(" | ",$_POST));
echo $this->input->post('e');
}


Am I missing something? the response from server are ok. but still the file created contains no data and echo prints empty. Any tips please? I have already tried method:'POST' instead of type:'POST'. Get variables pass away successfully.

Is this CI issue or Ajax because it is constant across ff,chrome and Opera

Answer

Try This Ajax :

 $.ajax({
        type: "POST",
        url: "http://www.abc.ca/types/add",
        data: postForm,           
        cache: "false",          
        success: function (result) {

            //result here is blank
            alert(result);
        },
        fail: function (result){
        alert(result);
        }


    });