【问题标题】:Display a fail alert when using "PUT" with xmlhttp将“PUT”与 xmlhttp 一起使用时显示失败警报
【发布时间】:2014-03-04 07:22:58
【问题描述】:

我目前正在使用以下方法将内容写回数据库:

xmlhttp.open("PUT","...",false);
xmlhttp.setRequestHeader("Content-type","application/xml");
xmlhttp.send((new XMLSerializer()).serializeToString(xmlDoc.getElementsByTagName("beanRepresentation")[i]));

如果失败,我想要一个警报,例如数据库不支持 PUT 或类似的东西。我怎样才能做到这一点?

【问题讨论】:

    标签: javascript xmlhttprequest


    【解决方案1】:

    你应该开始reading more about XMLHttpRequest

    要检查错误,您可以将函数绑定到错误事件:

    xmlhttp.addEventListener('error', errorCallback);
    

    如果在请求执行期间发生任何错误(服务器错误、连接错误等),将触发此回调。

    【讨论】:

      猜你喜欢
      • 2021-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-28
      相关资源
      最近更新 更多