Ajax调用Webservice Aways Fails [英] Ajax call to a Webservice Aways Fails

查看:110
本文介绍了Ajax调用Webservice Aways Fails的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用ajax(在按钮点击时)在HTML页面内进行简单的Web API调用。但那个电话总是失败。问题仅出在该API的ajax(按钮点击)调用上。在combobox中加载完美无缺。所以,我希望它不应该是一个跨域问题。

I am trying to make a simple web API call inside an HTML page using ajax (on button click). but that call always fail. Issue is only with ajax (on button click) call for that API. loading in combobox works perfectly fine. So, I hope it should not be a cross domain issue.

以下是导致问题的代码:

Following is the code where it causing trouble:

<body>

    <a class="offline-button" href="../index.html">Back</a>
    <input id="btnSayHello" type="button" value="Get Value From Ajax" /><br />

    <div id="example" class="k-content">

        <div class="demo-section">
            <h2>Products</h2>
            <input id="products" style="width: 250px" />
        </div>

        <script>
            $(document).ready(function() {
                $("#products").kendoDropDownList({
                    //dataTextField: "Name",
                    //dataValueField: "Name",
                    dataTextField: "ProductName",
                    dataValueField: "ProductID",
                    dataSource: {
                        transport: {
                            read: {
                                dataType: "jsonp",
                                url: "http://demos.kendoui.com/service/Products",
                            }
                        }
                    }
                });
            });

            $(function () {

                $("#btnSayHello").click(function () {
                    $.ajax({
                        type: "GET",
                        contentType: "jsonp",
                        //contentType: "application/json; charset=utf-8",
                        dataTypes: "jsonp",
                        processdata: true,
                        data: {},
                        url: "http://demos.kendoui.com/service/Products",
                        success: function (data) {
                            alert("Success");
                        },
                        error: function (result) {
                            window.alert(result.responseText);
                        }
                    });
                })
            });
        </script>

对于按钮点击的Ajax调用的 responseText ,它返回undefined

For button click's Ajax call's responseText it returns "undefined"

文档就绪功能的相同URL调用正常。并填充 ComboBox

Same URL call for Document ready function works fine. and populate that ComboBox.

可以在此链接

先谢谢大家的帮助!

推荐答案

好的,我得到了答案,问题在于 dataTypes 关键字。我将其更改为 dataType 并且有效。

Okay I got my answer and the problem is because of "dataTypes" keyword. I changed it to "dataType" and it worked.

嗯,我是Web技术的新手,最初我尝试在aspx页面中开发相同的代码,其中dataTypes工作得很好。因此,我尝试在普通的HTML文件中使用相同的代码库,但它不起作用。

Well, I am new to web technologies and initially I tried to develop the same code in aspx page where "dataTypes" works just fine. Therefore, I tried to use same code base in a normal HTML file and it didn't work.

因此,结论是 aspx 页面中的 dataTypes 可能会有一些不同的处理方式的 HTML5 即可。

So, the conclusion is there might be some different treatment for "dataTypes" in aspx pages as compare to HTML5.

这篇关于Ajax调用Webservice Aways Fails的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆