weixin_33739523 2015-10-27 17:17 采纳率: 0%
浏览 33

使用AJAX序列化日期

How do I serialize a date to use for ajax? I am using ajax to send a date over from a hidden input textbox and want to serialize it to run a query with coldfusion.

HTML (automatically receives date)

JS

var Tmrwdate = $('#TomorrowsDate'); 
console.log($(Tmrwdate).serialize());
    $.ajax({
            url: "proxy/TomorrowsDate.cfm",
            type: "post",
            dataType: "json",
            data: {date: Tmrwdate.serialize() },
            success: function (data) {
                console.log(data);
            }, 
            error: function (xhr, textStatus, errorThrown) {
                console.log(errorThrown);
            }
        });

proxy/TomorrowsDate.cfm

<cfset session.dealerwork.tomorrowsdate = form.TomorrowsDate >

<cfquery name="tomorrowTextArea">
    SELECT *
    FROM dbo.Dealer_Track_Work
    WHERE Date_Due = <cfqueryparam value="#session.dealerwork.tomorrowsdate#" /> 
    AND Date_Complete IS NULL       
</cfquery>


<cfoutput>#SerializeJSON(session.dealerwork.tomorrowsdate)#</cfoutput>

my console log from console.log($(Tmrwdate).serialize());

TomorrowsDate=10%2F28%2F2015
  • 写回答

2条回答 默认 最新

  • weixin_33721344 2015-10-27 17:20
    关注

    You shouldn't need to serialize a date, just send the value in your data argument.

    JS

    var Tmrwdate = $('#TomorrowsDate').val(); 
    
    $.ajax({
            url: "proxy/TomorrowsDate.cfm",
            type: "post",
            dataType: "json",
            data: {date: Tmrwdate },
            success: function (data) {
                console.log(data);
            }, 
            error: function (xhr, textStatus, errorThrown) {
                console.log(errorThrown);
            }
        });
    

    proxy/TomorrowsDate.cfm

    <cfset session.dealerwork.tomorrowsdate = form.TomorrowsDate >
    <cfset result = { TomorrowsDate = form.TomorrowsDate} />
    
    <cfquery name="tomorrowTextArea">
        SELECT *
        FROM dbo.Dealer_Track_Work
        WHERE Date_Due = <cfqueryparam value="#session.dealerwork.tomorrowsdate#" /> 
        AND Date_Complete IS NULL       
    </cfquery>
    
    
    <cfoutput>#SerializeJSON(result)#</cfoutput>
    
    评论

报告相同问题?

悬赏问题

  • ¥20 蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏