我有以下jquery函數,它應該將數據發佈到一個php函數,該函數在該函數中將其傳遞給外部腳本進行處理。 下面是我的jQuery函數:Jquery PHP將Json數據發佈到外部URL
function order_confirmation(json) {
$.ajax({
type: 'POST',
url: "<?php echo base_url(); ?>home/confirm_order_received/",
data: json,
contentType: 'application/json',
dataType: 'json',
success: function (data) {
console.log(data);
},
failure: function (errMsg) {
console.log(errMsg);
}
});
}
此功能應該通過JSON數據到我的PHP函數,它是下面的位置:
function confirm_order_received() {
$json = $this->input->post('json');
// Initialize curl
$curl = curl_init();
$externalscriptaddress = "http://197.237.132.178/api/order/order_upsert";
// Configure curl options
$opts = array(
CURLOPT_URL => $externalscriptaddress,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $json
);
// Set curl options
curl_setopt_array($curl, $opts);
// Get the results
$result = curl_exec($curl);
// Close resource
curl_close($curl);
echo $result;
}
我有,我應該怎樣訪問的問題從PHP方面的數據,我試圖通過帖子訪問它:$json = $this->input->post('json');
並將其傳遞到CURLOPT_POSTFIELDS => $json
但我得到一個錯誤,因爲沒有通過。請告知我如何將json數據傳遞給外部腳本?
您被指定JSON變量order_confirmation訪問它() – msvairam
可以顯示什麼是你在JavaScript –
嘗試的var_dump($ _ POST)使用JSON變量的值;並檢查發佈內容。另請嘗試var_dump($ this-> input-> post()); – shapeshifter