I have a problem with post data in jquery
This is my code:
$.ajax({
cache: false,
type: "POST",
url: '<?=base_url();?>cart/add_product1',
async: false,
data: {
job_id: item.job_id,
quantity: item.quantity,
price: item.price,
media_code: item.media_code,
product_id: item.layout_code,
product_name: item.product_name,
reedit_url: item.reedit_url,
thumb_url: item.thumb_url
},
success: function (response, textStatus, jqXHR) {
console.log('done!');
},
error: function (jqXHR, textStatus, errorThrown) {
console.log("The following error occured: " + textStatus, errorThrown);
}
})
I tried many thing, like add cache: flase, and added timestamp to the link but the problem is still
The code is work good in the other browsers
The code for the add_product1 function is:
public function add_product1 ()
{
print_r($_POST);
}
But the result is : Array()
Your help please
Thank you
Can you try this
data: {
"job_id": item.job_id,
"quantity": item.quantity,
"price": item.price,
"media_code": item.media_code,
"product_id": item.layout_code,
"product_name": item.product_name,
"reedit_url": item.reedit_url,
"thumb_url": item.thumb_url
},
Not really sure if this is the problem but it might be an IE quirk
The problem was that the variable item not defined. In IE should add var before the variable, but the other browsers ignoring this. My code was like this:
item = data.item[0];
$.ajax({
cache: false,
type: "POST",
url: '<?=base_url();?>cart/add_product1',
async: false,
data: {
job_id: item.job_id,
quantity: item.quantity,
price: item.price,
media_code: item.media_code,
product_id: item.layout_code,
product_name: item.product_name,
reedit_url: item.reedit_url,
thumb_url: item.thumb_url
},
success: function (response, textStatus, jqXHR) {
console.log('done!');
},
error: function (jqXHR, textStatus, errorThrown) {
console.log("The following error occured: " + textStatus, errorThrown);
}
})
I changed it to this:
var item = data.item[0];
$.ajax({
cache: false,
type: "POST",
url: '<?=base_url();?>cart/add_product1',
async: false,
data: {
job_id: item.job_id,
quantity: item.quantity,
price: item.price,
media_code: item.media_code,
product_id: item.layout_code,
product_name: item.product_name,
reedit_url: item.reedit_url,
thumb_url: item.thumb_url
},
success: function (response, textStatus, jqXHR) {
console.log('done!');
},
error: function (jqXHR, textStatus, errorThrown) {
console.log("The following error occured: " + textStatus, errorThrown);
}
})