0

给我一个 Web 服务(我想写在 ASP .Net 上),我收到这个错误,从 jQuery 调用它:

XMLHttpRequest cannot load http://www.hotelbeasain.com/webservice/wshotelbeasain.asmx?op=EstadoHabitacionesFechas. Origin http://hotel.local is not allowed by Access-Control-Allow-Origin.

如果我像这样在 python 中运行脚本:

from suds.client import Client
url = 'http://www.hotelbeasain.com/webservice/wshotelbeasain.asmx?WSDL'
client = Client(url)
# print client
hotel =  client.service.EstadoHabitacionesFechas()
print hotel
print type(hotel)

结果是这个:

(EstadoHabitacionesFechasResult){
   schema[] = 
      (schema){
         _id = "NewDataSet"
         element[] = 
            (element){
               _UseCurrentLocale = "true"
               _IsDataSet = "true"
               _MainDataTable = "TablaEstadoHabitacion"
               _name = "NewDataSet"
               complexType[] = 
                  (complexType){
                     choice[] = 
                        (choice){
                           _maxOccurs = "unbounded"
                           _minOccurs = "0"
                           element[] = 
                              (element){
                                 _name = "TablaEstadoHabitacion"
                                 complexType[] = 
                                    (complexType){
                                       sequence[] = 
                                          (sequence){
                                             element[] = 
                                                (element){
                                                   _type = "xs:int"
                                                   _name = "IdHabitacion"
                                                   _minOccurs = "0"
                                                },
                                                (element){
                                                   _type = "xs:string"
                                                   _name = "FechaEntrada"
                                                   _minOccurs = "0"
                                                },
                                                (element){
                                                   _type = "xs:string"
                                                   _name = "FechaSalida"
                                                   _minOccurs = "0"
                                                },
                                          },
                                    },
                              },
                        },
                  },
            },
      },
   diffgram[] = 
      (diffgram){
         DocumentElement[] = 
            (DocumentElement){
               TablaEstadoHabitacion[] = 
                  (TablaEstadoHabitacion){
                     _id = "TablaEstadoHabitacion1"
                     _rowOrder = "0"
                     _hasChanges = "inserted"
                     IdHabitacion[] = 
                        "1",
                     FechaEntrada[] = 
                        "23/05/2012",
                     FechaSalida[] = 
                        "31/12/2012",
                  },
                  (TablaEstadoHabitacion){
                     _id = "TablaEstadoHabitacion2"
                     _rowOrder = "1"
                     _hasChanges = "inserted"
                     IdHabitacion[] = 
                        "2",
                     FechaEntrada[] = 
                        "23/05/2012",
                     FechaSalida[] = 
                        "29/06/2012",
                  },
                  (TablaEstadoHabitacion){
                     _id = "TablaEstadoHabitacion3"
                     _rowOrder = "2"
                     _hasChanges = "inserted"
                     IdHabitacion[] = 
                        "2",
                     FechaEntrada[] = 
                        "29/06/2012",
                     FechaSalida[] = 
                        "01/07/2012",
                  },
                  (TablaEstadoHabitacion){
                     _id = "TablaEstadoHabitacion4"
                     _rowOrder = "3"
                     _hasChanges = "inserted"
                     IdHabitacion[] = 
                        "3",
                     FechaEntrada[] = 
                        "02/06/2012",
                     FechaSalida[] = 
                        "03/06/2012",
                  },
                  (TablaEstadoHabitacion){
                     _id = "TablaEstadoHabitacion5"
                     _rowOrder = "4"
                     _hasChanges = "inserted"
                     IdHabitacion[] = 
                        "3",
                     FechaEntrada[] = 
                        "29/06/2012",
                     FechaSalida[] = 
                        "01/07/2012",
                  },
                  (TablaEstadoHabitacion){
                     _id = "TablaEstadoHabitacion6"
                     _rowOrder = "5"
                     _hasChanges = "inserted"
                     IdHabitacion[] = 
                        "4",
                     FechaEntrada[] = 
                        "29/06/2012",
                     FechaSalida[] = 
                        "01/07/2012",
                  },
                  (TablaEstadoHabitacion){
                     _id = "TablaEstadoHabitacion7"
                     _rowOrder = "6"
                     _hasChanges = "inserted"
                     IdHabitacion[] = 
                        "5",
                     FechaEntrada[] = 
                        "02/06/2012",
                     FechaSalida[] = 
                        "03/06/2012",
                  },
                  (TablaEstadoHabitacion){
                     _id = "TablaEstadoHabitacion8"
                     _rowOrder = "7"
                     _hasChanges = "inserted"
                     IdHabitacion[] = 
                        "5",
                     FechaEntrada[] = 
                        "29/06/2012",
                     FechaSalida[] = 
                        "01/07/2012",
                  },
                  (TablaEstadoHabitacion){
                     _id = "TablaEstadoHabitacion9"
                     _rowOrder = "8"
                     _hasChanges = "inserted"
                     IdHabitacion[] = 
                        "6",
                     FechaEntrada[] = 
                        "02/06/2012",
                     FechaSalida[] = 
                        "03/06/2012",
                  },
                  (TablaEstadoHabitacion){
                     _id = "TablaEstadoHabitacion10"
                     _rowOrder = "9"
                     _hasChanges = "inserted"
                     IdHabitacion[] = 
                        "6",
                     FechaEntrada[] = 
                        "29/06/2012",
                     FechaSalida[] = 
                        "01/07/2012",
                  },
                  (TablaEstadoHabitacion){
                     _id = "TablaEstadoHabitacion11"
                     _rowOrder = "10"
                     _hasChanges = "inserted"
                     IdHabitacion[] = 
                        "7",
                     FechaEntrada[] = 
                        "25/05/2012",
                     FechaSalida[] = 
                        "28/05/2012",
                  },
                  (TablaEstadoHabitacion){
                     _id = "TablaEstadoHabitacion12"
                     _rowOrder = "11"
                     _hasChanges = "inserted"
                     IdHabitacion[] = 
                        "7",
                     FechaEntrada[] = 
                        "02/06/2012",
                     FechaSalida[] = 
                        "03/06/2012",
                  },
                  (TablaEstadoHabitacion){
                     _id = "TablaEstadoHabitacion13"
                     _rowOrder = "12"
                     _hasChanges = "inserted"
                     IdHabitacion[] = 
                        "7",
                     FechaEntrada[] = 
                        "29/06/2012",
                     FechaSalida[] = 
                        "01/07/2012",
                  },
                  (TablaEstadoHabitacion){
                     _id = "TablaEstadoHabitacion14"
                     _rowOrder = "13"
                     _hasChanges = "inserted"
                     IdHabitacion[] = 
                        "8",
                     FechaEntrada[] = 
                        "25/05/2012",
                     FechaSalida[] = 
                        "28/05/2012",
                  },
                  (TablaEstadoHabitacion){
                     _id = "TablaEstadoHabitacion15"
                     _rowOrder = "14"
                     _hasChanges = "inserted"
                     IdHabitacion[] = 
                        "8",
                     FechaEntrada[] = 
                        "02/06/2012",
                     FechaSalida[] = 
                        "03/06/2012",
                  },
                  (TablaEstadoHabitacion){
                     _id = "TablaEstadoHabitacion16"
                     _rowOrder = "15"
                     _hasChanges = "inserted"
                     IdHabitacion[] = 
                        "9",
                     FechaEntrada[] = 
                        "25/05/2012",
                     FechaSalida[] = 
                        "28/05/2012",
                  },
                  (TablaEstadoHabitacion){
                     _id = "TablaEstadoHabitacion17"
                     _rowOrder = "16"
                     _hasChanges = "inserted"
                     IdHabitacion[] = 
                        "9",
                     FechaEntrada[] = 
                        "01/06/2012",
                     FechaSalida[] = 
                        "03/06/2012",
                  },
                  (TablaEstadoHabitacion){
                     _id = "TablaEstadoHabitacion18"
                     _rowOrder = "17"
                     _hasChanges = "inserted"
                     IdHabitacion[] = 
                        "9",
                     FechaEntrada[] = 
                        "29/06/2012",
                     FechaSalida[] = 
                        "01/07/2012",
                  },
                  (TablaEstadoHabitacion){
                     _id = "TablaEstadoHabitacion19"
                     _rowOrder = "18"
                     _hasChanges = "inserted"
                     IdHabitacion[] = 
                        "10",
                     FechaEntrada[] = 
                        "25/05/2012",
                     FechaSalida[] = 
                        "28/05/2012",
                  },
                  (TablaEstadoHabitacion){
                     _id = "TablaEstadoHabitacion20"
                     _rowOrder = "19"
                     _hasChanges = "inserted"
                     IdHabitacion[] = 
                        "10",
                     FechaEntrada[] = 
                        "02/06/2012",
                     FechaSalida[] = 
                        "03/06/2012",
                  },
            },
      },
 }
<type 'instance'>
[Finished in 0.3s]

因此,从 python 中,Web 服务正在运行,但是当我从我的 jQuery 脚本中调用它时,它不是。这是我的 jQuery 脚本

$.ajax({
            type: "POST",
            url: "http://www.hotelbeasain.com/webservice/wshotelbeasain.asmx?op=EstadoHabitacionesFechas",
            data: '{}',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (resul) {
                // if (resul.d)
                    alert('El usuario es válido.');
                // else
                    // alert('El usuairo es inválido.');
            },
            error:function (xhr, ajaxOptions, thrownError){
                    alert(xhr.status);
                    alert(thrownError);
                }
        });

任何帮助或线索?提前致谢。

4

2 回答 2

1

似乎您收到的错误与同源策略有关

于 2012-07-03T09:38:42.260 回答
0

尝试将 jquery ajax 调用中的 url 从: http ://www.hotelbeasain.com/webservice/wshotelbeasain.asmx?op=EstadoHabitacionesFechas 更改为:http : //www.hotelbeasain.com/webservice/wshotelbeasain.asmx /EstadoHabitacionesFechas

于 2012-07-03T09:50:42.643 回答