无法在Firefox和IE9中获取数据,但在Chrome和Safari中可以正常工作
Can't get data in Firefox and IE9 but it works fine in Chrome and Safari
我有这个方法
function callCommentservice() {
try {
// Comment Service Url
var getCommentServiceUrl = self.commentsServiceUrl + self.getRating + "tenantId=" + self.tenantId + "&ratedObjectTypeId=" + self.ratedObjectTypeId + "&ratedObjectId=" + self.ratedObjectId + "&ratingType=" + self.ratingType + "&start=" + self.start + "&totalRecordsNeeded=" + self.totalRecordsNeeded;
$.ajax({
type: "GET",
url: getCommentServiceUrl,
contentType: "application/json",
timeout: 5000,
beforeSend: function (xhr) {
xhr.setRequestHeader("Accept", "application/json");
},
dataType: "json",
success: function (data) {
alert("I m in here.............!!!!");
// if (success == data) {
// Assigning totalRecordsNeeded value to global variable pagination_parameters.pageSize
pagination_parameters.pageSize = self.totalRecordsNeeded;
//Printing on a console.
debug("get comments url: " + getCommentServiceUrl);
// Calling Service in order to get data.
// $.getJSON(getCommentServiceUrl + "&callback=?", function (data) {
var emptyCommentHyperlink = document.getElementById('emptyCommentHyperlink');
// when there is no comment available in a service than this block will work.
if (data.length == 0) {
emptyCommentHyperlink.style.display = 'block';
//emptyCommentHyperlink.onclick = addCommentsBox;
$("#emptyCommentHyperlink").click(addCommentsBox);
}
else {
emptyCommentHyperlink.style.display = 'none';
}
//printing on a console.
debug("Date from the get service:" + data);
//alert(data);
// Changing date format of a service element AddedDateTime.
for (var key = 0; key < data.length; key++) {
var dataArray = data[key];
// Printing on console.
debug("data Array after the data object:" + dataArray);
var jsonDate = dataArray.AddedDateTime; //AddedDateTime is the service element.'
// Printing on a console.
debug("converted Time" + jsonDate);
var oneSecond = 1000; // milliseconds in one seconds
// changing format of the AddedDateTime
var date = new Date(parseInt(jsonDate.substring(6)));
var year = date.getFullYear(); // 2011
var day = date.getDay();
var exactdate = date.getDate();
var month = date.getMonth();
var hours = date.getHours();
var minutes = date.getMinutes();
var month_names_short = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
// Fromating Absolute time over tooltip.
if (hours > 12) {
hours = hours - 12;
var exact = zeroPad(hours) + ":" + zeroPad(minutes) + " PM" + ", " + exactdate + " " + month_names_short[month] + " " + year;
}
else {
var exact = zeroPad(hours) + ":" + zeroPad(minutes) + " AM" + ", " + exactdate + " " + month_names_short[month] + " " + year;
}
// subtracting current date with the comment date.
var finalDate = Math.abs(new Date() - date) / oneSecond;
dataArray.time_duration = new TimeSpan(finalDate).toString();
// Printing on a console.
debug("finalDate: " + dataArray.time_duration);
//alert(dataArray.time_duration);
dataArray.Absolute_Date = exact;
}
// Extracting TotalCount from service.
var totalComments = data[0].TotalCount;
// alert(totalComments);
//Calling paging Function
pages(totalComments);
//Making the commenttable empty.
$('#commentDiv').empty();
// Printing on a console.
debug("data before mactache" + data);
var comments = { "Comments": data };
var html = Mustache.to_html(self.template_html, comments);
var target_div = document.getElementById("commentDiv");
target_div.innerHTML = html;
//alert("target_div");
// });
},
// },
error: function (xhr, ajaxOptions, thrownError) {
debug(xhr);
var errorMsg = document.getElementById('ErrorLable');
errorMsg.style.display = "block";
}
});
}
catch (err) {
//Printing on a console.
debug("callCommentservice");
debug(err);
}
}
此方法在Chrome和Safari中工作良好,但在i.e. 9和firefox中不工作,我在firefox请求头中收到错误405如下:-
响应头允许
获取内容长度1565内容类型text/html;charset=UTF-8 Server Microsoft-IIS/7.5 X-Powered-By ASP。网Access-Control-Allow-Orig……*Access-Control-Allow-Meth……POST、GET、选择Access-Control-Allow-Head……内容类型,接受Access-Control-Max-Age 1728000日期星期三,2011年12月14日10:30:43 GMT请求头Host services.farooq.tv用户代理Mozilla/5.0(Windows NT 6.1;WOW64;rv:8.0.1)壁虎/20100101 Firefox/8.0.1接受text/html, application/xhtml + xml, application/xml; q = 0.9 /; q = 0.8Accept-Encoding gzip, deflateAccept-Charset iso - 8859 - 1, utf - 8; q = 0.7 *; q = 0.7连接维生起源http://marketplace.softech-lp35.softech.usAccess-Control-Request-Me……得到Access-Control-Request-He……内容类型
在contentType: "application/json"中有一个问题,我已经从$中删除了它。
- Javascript:selenium Web驱动程序isDisplayed()不工作
- jQuery UI自动完成突然停止工作
- AngularJS UI路由器不能像ng路由器那样工作
- HTML5音频加载和播放获胜'我不能在iPad上工作
- JavaScript打印功能使日历停止工作
- Javascript.getHours()工作不正常
- 为什么这在IE中的工作方式与在Firefox中不同
- 视频HTML没有'无法在Internet Explorer 11上工作
- 扩展移相器按钮类不工作
- Firebase迁移-简单的Firebase.set没有'不再工作了——旧的还是新的
- 谷歌地图不是以HTML显示,而是在JS Fiddle上工作
- 正在尝试使用if和else添加类,但无法正常工作
- Jquery FadeIn FadeOut 只工作一次
- Foreach无法在Typescript中工作
- 另一个ajax调用中的Jquery ajax调用在for循环中没有按预期工作
- 为什么不是't窗口.恢复正常工作吗?(javascript/jquery)
- JS可以在Chrome中工作,但不能在Firefox中工作
- ajaxToolkit PopupControlExtender不工作.过时的
- HTML标记在脚本标记中工作
- javascript扫雷器floodfill算法不能正常工作