本文介绍了AJAX调用返回日期问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 您好, 我的控制器中的,json结果返回开始日期为04/04/2017但是当我在AJAX中打印开始日期时,会在视图中显示返回as /日期(1488133800000)/ 我操纵开始日期如下,但它打印4/4/2017 。我需要打印04/04/2017。 我该怎么做? $。ajax({ url:'@ Url.Action(JobsServiceProviderC,PostWork)',类型:发布, dataType:json ,数据:{KeywordSearch:strKeywordSearch},成功:函数(数据){ $(#tblJobs> tbody)。html(); if(data.data.length> 0){ for(var i = 0; i< data.data.length; i ++){ tr = $('< tr /> '); var SDate = new Date(eval('new'+ data.data [i] .StartDate.replace(/ \ // g,''))); var formattedSDate = SDate.getMonth()+ 1 +'/'+ SDate.getDate()+'/'+ SDate.getFullYear(); < pre> $('#tblJobs> tbody')。append(tr ); }},错误:函数(jqXHR,textStatus,errorThrown){ $(。loading)。css(display,none); } }); 谢谢 我的尝试: var SDate = new Date(eval('new'+ data.data [i] .StartDate.replace(/ \ // g,''))); var formattedSDate = SDate.getMonth()+ 1 +'/'+ SDate.getDate()+'/'+ SDate.getFullYear(); tr.append(< td>+ formattedSDate +< / td>); 解决方案 .ajax({ url:'@ Url.Action(JobsServiceProviderC,PostWork)',类型:发布, dataType:json,数据:{KeywordSearch:strKeywordSearch},成功:函数(数据){ (#tblJobs> tbody)。html(); if(data.data.length> 0){ for(var i = 0; i< data.data.length; i ++){ tr = ('< tr />'); var SDate = new Date(eval('new'+ data.data [i] .StartDate.replace(/ \ // g,' '))); var formattedSDate = SDate.getMonth()+ 1 +'/'+ SDate.getDate()+'/'+ SDate.getFullYear(); < pre> Hello,in my Controller, json result returns start date as 04/04/2017 but when I print start date in AJAX call return in view it displays as /Date(1488133800000)/I manipulated start date as below but it prints 4/4/2017.I need to print 04/04/2017.how can I do that?$.ajax({url: '@Url.Action("JobsServiceProviderC", "PostWork")',type: "Post",dataType: "json",data: { KeywordSearch: strKeywordSearch },success: function (data) {$("#tblJobs > tbody").html("");if (data.data.length > 0) {for (var i = 0; i < data.data.length; i++) {tr = $('<tr/>');var SDate = new Date(eval('new' + data.data[i].StartDate.replace(/\//g, ' ')));var formattedSDate = SDate.getMonth() + 1 + '/' + SDate.getDate() + '/' + SDate.getFullYear();<pre>$('#tblJobs > tbody').append(tr);}},error: function (jqXHR, textStatus, errorThrown) { $(".loading").css("display", "none");}});ThanksWhat I have tried:var SDate = new Date(eval('new' + data.data[i].StartDate.replace(/\//g, ' '))); var formattedSDate = SDate.getMonth() + 1 + '/' + SDate.getDate() + '/' + SDate.getFullYear();tr.append("<td>" + formattedSDate + "</td>"); 解决方案 .ajax({url: '@Url.Action("JobsServiceProviderC", "PostWork")',type: "Post",dataType: "json",data: { KeywordSearch: strKeywordSearch },success: function (data) {("#tblJobs > tbody").html("");if (data.data.length > 0) {for (var i = 0; i < data.data.length; i++) {tr =('<tr/>');var SDate = new Date(eval('new' + data.data[i].StartDate.replace(/\//g, ' ')));var formattedSDate = SDate.getMonth() + 1 + '/' + SDate.getDate() + '/' + SDate.getFullYear();<pre> 这篇关于AJAX调用返回日期问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-23 06:15