jQuery AJAX post 不工作,但适用于curl

发布于 2024-08-02 07:52:04 字数 1692 浏览 3 评论 0原文

我正在尝试使用 jQuery(对于 BaseCamp API)通过 ajax 发出发布请求,但我似乎无法让它工作。我可以使用curl 让它正常工作,所以我知道这是我在使用jQuery 时做错的事情。这是有效的curl 命令:

curl -H "Accept: application/xml" -H "Content-Type: application/xml" -u my.user.name:my.password -d "<time-entry><person-id>123456</person-id><date>08/23/2009</date><hours>8</hours><description>This is a test.</description></time-entry>" https://my.url.updatelog.com/todo_items/1234567/time_entries.xml

这是我正在尝试使用jQuery 的代码:

var post_url = bc_base_url + "/todo_items/" + todo_id + "/time_entries.xml";
var xmlData = "<time-entry><person-id>" + bc_user_id + "</person-id>" + 
        "<date>" + date + "</date>" +
        "<hours>" + time + "</hours>" +
        "<description>" + description + "</description>" + 
        "</time-entry>";
$.ajax({
                type: "POST",
                url: post_url,
                data: xmlData,
                dataType: "xml",
                contentType: "application/xml",
                username: "my.user.name",
                password: "my.password",
                processData: false,
                success: function(msg) {
                  alert("successfully posted! msg: " + msg + ", responseText = " + this.responseText);
                },
                error: function (xmlHttpRequest, textStatus, errorThrown) {
                  alert("error : " + textStatus + ", errorThrown = " + errorThrown);
                  alert("this.reponseText = " + this.responseText);
                }
            })

有人有任何想法吗?

谢谢!

I'm trying to make a post request via ajax using jQuery (for the BaseCamp API), and I can't seem to get it to work. I can get it to work using curl just fine, so I know it's something I'm doing wrong with jQuery. Here's the curl command which works:

curl -H "Accept: application/xml" -H "Content-Type: application/xml" -u my.user.name:my.password -d "<time-entry><person-id>123456</person-id><date>08/23/2009</date><hours>8</hours><description>This is a test.</description></time-entry>" https://my.url.updatelog.com/todo_items/1234567/time_entries.xml

and here's the code I'm trying with jQuery:

var post_url = bc_base_url + "/todo_items/" + todo_id + "/time_entries.xml";
var xmlData = "<time-entry><person-id>" + bc_user_id + "</person-id>" + 
        "<date>" + date + "</date>" +
        "<hours>" + time + "</hours>" +
        "<description>" + description + "</description>" + 
        "</time-entry>";
$.ajax({
                type: "POST",
                url: post_url,
                data: xmlData,
                dataType: "xml",
                contentType: "application/xml",
                username: "my.user.name",
                password: "my.password",
                processData: false,
                success: function(msg) {
                  alert("successfully posted! msg: " + msg + ", responseText = " + this.responseText);
                },
                error: function (xmlHttpRequest, textStatus, errorThrown) {
                  alert("error : " + textStatus + ", errorThrown = " + errorThrown);
                  alert("this.reponseText = " + this.responseText);
                }
            })

Anyone have any ideas?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烧了回忆取暖 2024-08-09 07:52:04

正如 karim79 所说,您不能发布到不同的域。

请参阅 Nathan 的帖子 了解更多选项。

As karim79 said, you can't post to a different domain.

See Nathan's post for more options.

黯然 2024-08-09 07:52:04

将其发布到您的服务器,从应用程序代码将帖子传递到 Basecamp,然后将消息传回。

Post it to your server, pass the post onto basecamp from the application code, and pass the messages back down.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文