【问题标题】:XMLHttpRequest in jQueryjQuery 中的 XMLHttpRequest
【发布时间】:2014-03-20 07:25:03
【问题描述】:

我对 jQuery 很陌生,在这里需要帮助。我一直在 JavaScript 中使用 XMLHttpRequest,它调用 WCF 服务进行进一步处理。此服务不返回任何内容。只需要一个参数并处理不同的不同模块。

    function CallMathsService(str) {
    xmlhttp = null;
    var url = "http://localhost/Maths/" + str;

    if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
    }

    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            if (xmlhttp.responseText != null) {
        alert("Success.");
            }

        }
    }
    xmlhttp.open("GET", url, false);
    xmlhttp.send();

}

我需要用 jQuery 重写它。有人可以帮忙吗?

【问题讨论】:

  • 那么,如果您遇到一些具体问题,请发布它
  • 非常感谢您的回复。但是我犯了一个愚蠢的错误;一直在创建一个 html 文件,忘记添加以下脚本标签。 再次感谢。

标签: javascript jquery wcf


【解决方案1】:

它们的作用非常相似。

jQuery.ajax() -> https://api.jquery.com/jQuery.ajax/ jQuery.get() -> https://api.jquery.com/jQuery.get/

【讨论】:

  • 非常感谢您的回复。但是我犯了一个愚蠢的错误;一直在创建一个 html 文件,忘记添加以下脚本标签。 再次感谢。
【解决方案2】:

使用 jquery

{ xhr: function () {
            var xhr = $.ajaxSettings.xhr();
            xhr.onprogress = function (evt) {
                // For downloads
                alert("test");
                if (evt.lengthComputable) {
                    var percentComplete = evt.loaded / evt.total;
                    percentComplete = parseInt(percentComplete * 100);
                    $('.myprogress').text(percentComplete + '%');
                    $('.myprogress').css('width', percentComplete + '%');
                }
            };
            return xhr;
        },
}

【讨论】:

    猜你喜欢
    • 2010-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-11
    • 2011-07-06
    • 2015-02-28
    相关资源
    最近更新 更多