【问题标题】:jQuery AJAX post not working, but works with curljQuery AJAX 帖子不起作用,但适用于 curl
【发布时间】:2010-11-22 10:45:14
【问题描述】:

我正在尝试使用 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);
                }
            })

有人有什么想法吗?

谢谢!

【问题讨论】:

  • 在 Firebug 中查看时返回的错误是什么?会不会是跨域问题?
  • 您是在同一个域发帖吗?
  • 仅供参考,接受答案中的链接会转到 Go-Daddy 停放的域页面。
  • 没关系,@JoshuaMiller,我将其替换为指向 archive.org 页面副本的链接。

标签: jquery ajax post curl basecamp


【解决方案1】:

正如 karim79 所说,您不能发布到其他域。

更多选项请参见Nathan's post

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-02
      • 1970-01-01
      • 2015-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多