1

I have given a JSON webservice link, under which we have data and wanted to show it on html table using ajax jWuery. If I download it from IE it works locally by using .json format, but webservice link doesn't work. I have checked whether link is working or not but its working in JSON viewer. What to do?

$(document).ready(function() {
    $.ajax({  
       type: "GET",
       data : "{}",
       contentType: "application/json",
       //url: 'myfile.json',
       url: 'http://107.22.160.4/ICatService/Service.svc/GetEvent/10/iphone2x',
       dataType: "json",
       success: function(data) {  
         $.each(data.Get_TappyokaResult, function(index, data){
               var tblRow = "<tr>"+
                             "<td>"+data.Back_id+"</td>"+
                             "<td><img src="+data.Back_image+" class=rowimg /></td>\n"+
                             "<td>"+data.Back_type+"</td>\n"+
                             "<td>"+data.DateModified+"</td>"+
                            "</tr>"
               $(tblRow).appendTo(".dataTable");
               $('table tr:odd').addClass('oddrow');
               $('.dataTable tr:even').addClass('evenrow');
        });
     },  
     error: function(data){  
           alert("error");
     }  
  });
});

myfile.json LOCAL FILE ---------------------------------

{
 "Get_ICatelog_EventResult":[
      {
        "Date":"26\/07\/2012", "Description":"sample event", "Event_Id":5, "Heading":"sample", "Image":"http:\/\/thisisswitch.com\/ICatalogsite\/EventImage\/fc8e84f2-6729-42c0-8e0e-c6961edd2df5.JPG", "Status":0, "Time":"14:00:00", "User_Id":10
      }
  ]
}
4

2 回答 2

0

如果您可以控制(或您认识的人)网络服务,您可以将输出格式更改为 jsonp http://en.wikipedia.org/wiki/JSONP http://api.jquery.com/jQuery.getJSON /

于 2012-08-02T16:17:11.443 回答
0

你在使用网络服务器吗?如果不?确保你这样做。file:/// 有 ajax 请求的问题。如果你是,你可能会去另一个地方。( http://107.22.160.4) 所以这是一个跨源问题。

ajax 请求的来源需要与目标具有相同的协议 (http/https) 域 (domain.com) 和端口号(默认为 80)。

有一些解决方法,如CORS(跨源资源共享)提供正确的标头信息,您将能够访问另一个来源的日期,但大多数情况下需要您能够在服务器端设置它。

另一种选择是在您的服务器内转发流量。

或者使用 php 代理文件。该文件为您访问数据,您可以安全地访问数据或修改标题,以便您可以使用CORS访问它们

这是php示例

您还可以使用 flash 代理或任何类型的后端语言(asp、jsp、...)

于 2012-08-02T08:03:25.407 回答