Php 使用JSON从Jquery访问WCF

Php 使用JSON从Jquery访问WCF,php,jquery,html,json,wcf,Php,Jquery,Html,Json,Wcf,嗨,我正在尝试访问一个WCF服务,该服务使用JQuery返回一个JSON数组,但它不工作。但是,当我使用互联网上的php服务时,它是有效的。 请告诉我哪里出了问题 我的c班 在浏览器中加载时得到的响应 [{"id":"1","name":"test"},{"id":"2","name":"test"}] php web服务的URL 我的html代码 <script type="text/javascript"> $(document).ready(function

嗨,我正在尝试访问一个WCF服务,该服务使用JQuery返回一个JSON数组,但它不工作。但是,当我使用互联网上的php服务时,它是有效的。 请告诉我哪里出了问题

我的c班

在浏览器中加载时得到的响应

[{"id":"1","name":"test"},{"id":"2","name":"test"}]
php web服务的URL

我的html代码

<script type="text/javascript">
        $(document).ready(function(){

    $.ajax({
      url: "http://localhost:51220/Service1.svc/getdata",
      success: function(result){
        alert(result);
      },
      dataType: "jsonp"
    });
    });
</script>

$(文档).ready(函数(){
$.ajax({
url:“http://localhost:51220/Service1.svc/getdata",
成功:功能(结果){
警报(结果);
},
数据类型:“jsonp”
});
});

当我使用它时,我得到了错误0,但当我使用php服务时,我得到了数组。

请尝试以下代码

$.ajax({
                type: "GET",
                url: "http://localhost:51220/Service1.svc/getdata",
                processData: false,
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    alert(result);
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    alert(textStatus + ' / ' + errorThrown);
                }
            })

为什么在本地主机中使用jsonp?还可以在配置文件中显示端点吗?
$.ajax({
                type: "GET",
                url: "http://localhost:51220/Service1.svc/getdata",
                processData: false,
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    alert(result);
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    alert(textStatus + ' / ' + errorThrown);
                }
            })