我正在尝试使用 POST 方法在 jquery 中使用 $.ajax() 将 JSON 对象从我的纯 html 页面发送到 datapower 端点。fire bug 中的响应标头给了我“内部服务器错误”,请任何人告诉我我在这里做错了什么:HTTP/1.1 500 Error X-Backside-Transport: FAIL FAIL Content-Type: text/xml Connection: close
我的 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);
}
}
});
});
});