我想發送一個JSON對象使用jquery中的$ .ajax()與一個POST方法,從我的純html頁面,到一個數據端點endpoint.the響應標題在火災bug給我「內部服務器錯誤」,請任何一個告訴我,我在這裏做錯了: HTTP/1.1 500錯誤 X-Backside-Transport:失敗失敗 內容類型:文本/ xml 連接:接近
我的jQuery代碼看起來是這樣的:
$(document).ready(function() {
$('#btn_submitcallback').click(function() {
//add the values we need for the API to an object
var objCallbackData = new Object;
var d = new Date();
var dat = d.getDate();
var mon = d.getMonth() + 1;
var year = d.getFullYear();
var todayDate = dat + "/" + mon + "/" + year;
alert("inside submit callback");
//build the object
objCallbackData.Store_Code = "POO726"; //$('#sel_title').val();
objCallbackData.Title = $('#sel_title').val();
objCallbackData.First_Name = $('#txt_firstname').val();
objCallbackData.Last_Name = $('#txt_surname').val();
objCallbackData.House_Number = $('#txt_houseno').val();
objCallbackData.Street = $('#txt_streetname').val();
objCallbackData.City = $('#txt_city').val();
objCallbackData.Post_Code = $('#txt_postcode').val();
objCallbackData.Email = $('#txt_email').val();
objCallbackData.Phone_Number = $('#txt_phone').val();
objCallbackData.Project_Type = "Bathroom";
objCallbackData.Callbacktime_Morning = "Y";
objCallbackData.Callbacktime_Afternoon = "Y";
objCallbackData.Callbacktime_Evening = "N";
objCallbackData.Callbacktime_Weekend = "N";
objCallbackData.Callbacktime_Weekday = "Y";
objCallbackData.Helparea_Measuring = "Y";
objCallbackData.Helparea_Designing = "N";
objCallbackData.Helparea_Usingspaces = "N";
objCallbackData.Helparea_Services = "N";
objCallbackData.Helparea_Productinfo = "N";
objCallbackData.Status = "O";
objCallbackData.Date = todayDate;
// alert(objCallbackData.date);
//turn the object in to a JSON string
var myJson = JSON.stringify(objCallbackData);
alert(myJson);
$.ajax({
type: 'POST',
url: 'http://xb629050-s1.uk.b-and-q.com:9340/api/callback',
contentType: 'application/json; charset=utf-8',
data: myJson,
dataType: 'json',
success: function() {
alert("good");
},
error: function (xhr, status) {
switch (status) {
case 404:
alert('File not found');
break;
case 500:
alert('Server error');
break;
case 0:
alert('Request aborted');
break;
default:
alert('Unknown error: ' + xhr.statusText);
}
}
});
});
});
嘗試刪除從'contentType' – 2013-04-20 10:44:39
了'charset'試圖消除字符集..no快樂!! :( – user2301878 2013-04-20 11:14:19