开发者

Sending literal date in javascript on ajax post

Im have been given a web service to use that takes two dates for before and after as strings, I cannot change the web service.

e.g http://somedomain/restserver.aspx?method=date&after=2011-05-11%2000:00:00&before=2011-05-11%2023:59:00&callback=foo

The url works when i enter it in the browser but when I try entering it in code it sends a + instead of the space and the hex values for the colons.

my code goes as follows:

var t = new Date(2011, 05, 11, 00, 00, 00);
    var a = "" + t.getFullYear() + "-" + t.getMonth() + "-" + t.getDate() + " 0" + t.getHours() + ":0" + t.getMinutes() + ":0" + t.getSeconds();    

        $.getJSON("http://somedomain/restserver.aspx?&callback=?",
        {
            method: "date",
            after: a,
            before: a,
            format: "xml"
        },
        function(json) {
            al开发者_运维百科ert("success");

        });

It is trying to send: http://somedomain/restserver.aspx?&callback=?&method=date&after=2011-5-11+00%3A00%3A00&before=2011-5-11%252023%253a59%3A00&format=xml

Is there a way to send a space and a colon literally.

Any help with this would be much appreciated thanks


Try doing

$.getJSON("http://example.com/restserver.aspx?after=" + a + "&before" + a + "&callback=?",
        {
            method: "date",
            format: "xml"
        },
        function(json) {
            alert("success");

        });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜