至尊寶的傳說
2023-11-02 21:05:01
對于以下代碼獲取輸出$response=array(); $response['wheel_deg_end'] = (360*(ceil($wheel->wheel_spin_time/3))) + (360 - (($wheel_slice_number * 30) - 30)) + rand(-5,5);$response['wheel_time_end'] = $wheel->wheel_spin_time * 1000;$response['success'] = true; $ab = json_encode($response,JSON_NUMERIC_CHECK);echo $ab;輸出:"{"wheel_deg_end":1743,"wheel_time_end":10000,"success":true}"Json 解析錯誤:jQuery.ajax({ url: couponspining_ajaxurl, type: 'POST', data: { action: 'couponspining_wheel_run', form_data: form_data, preview_key: this.preview_key }, context: this,}).done(function(json){ this.submit_form_done(jQuery.parseJSON(json));});未捕獲的語法錯誤:JSON.parse:JSON數據submit_form的第3行第1列出現意外字符 http://localhost/shopify-php-app/src/public/assets/js/couponspining1.js:210
3 回答

慕萊塢森
TA貢獻1810條經驗 獲得超4個贊
只需將解析 json 行從
this.submit_form_done(jQuery.parseJSON(json));
到
this.submit_form_done(json);
因為如果 AJAX 調用的配置具有 dataType: json,您將獲得一個 JavaScript 對象,因此不再需要使用 JSON.parse()。

陪伴而非守候
TA貢獻1757條經驗 獲得超8個贊
"{"wheel_deg_end":1743,"wheel_time_end":10000,"success":true}"
不是有效的 json 字符串。
哪個應該是{"wheel_deg_end":1743,"wheel_time_end":10000,"success":true}

料青山看我應如是
TA貢獻1772條經驗 獲得超8個贊
將內容類型設置為 json:
jQuery.ajax({
url: couponspining_ajaxurl,
type: "POST",
contentType: "application/json",
data: {
action: "couponspining_wheel_run",
form_data: form_data,
preview_key: this.preview_key
},
context: this
}).done(function(json) {
this.submit_form_done(jQuery.parseJSON(json));
});
添加回答
舉報
0/150
提交
取消