Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 访问控制不允许对金字塔的ajax请求返回原点允许原点_Python_Ajax_Xmlhttprequest_Pyramid - Fatal编程技术网

Python 访问控制不允许对金字塔的ajax请求返回原点允许原点

Python 访问控制不允许对金字塔的ajax请求返回原点允许原点,python,ajax,xmlhttprequest,pyramid,Python,Ajax,Xmlhttprequest,Pyramid,我正在使用python pyramid,基本上我已经定义了这样一个路由: config.add_route('metaschemaxml', '/metaschema/{id}/xml') @view_config(route_name='metaschemaxml', renderer='string') def metaxml_view(request): schema = request.matchdict['id'] urlparams = request.query_stri

我正在使用python pyramid,基本上我已经定义了这样一个路由:

config.add_route('metaschemaxml', '/metaschema/{id}/xml')
@view_config(route_name='metaschemaxml', renderer='string')
def metaxml_view(request):
  schema = request.matchdict['id']
  urlparams = request.query_string
  urlparams.strip()
  required = 0
  for x in urlparams.split(','):
      if "required=1" in x:
          required = 1
  rxml = '<?xml version="1.0" encoding="utf-8"?><eroot></eroot>'

  try:
      tags = DBSession.query(mtemplatexelem_model).filter(mtemplatexelem_model.template_id == int(schema)).order_by(mtemplatexelem_model.xelem_id).all()
      rxml = getXMLFromQuery(tags, required)
  except DBAPIError:
      return Response("Error in DB", content_type='text/plain', status_int=500)

  return Response(rxml, content_type='text/xml', charset='utf8')
视图映射metashemaxml如下所示:

config.add_route('metaschemaxml', '/metaschema/{id}/xml')
@view_config(route_name='metaschemaxml', renderer='string')
def metaxml_view(request):
  schema = request.matchdict['id']
  urlparams = request.query_string
  urlparams.strip()
  required = 0
  for x in urlparams.split(','):
      if "required=1" in x:
          required = 1
  rxml = '<?xml version="1.0" encoding="utf-8"?><eroot></eroot>'

  try:
      tags = DBSession.query(mtemplatexelem_model).filter(mtemplatexelem_model.template_id == int(schema)).order_by(mtemplatexelem_model.xelem_id).all()
      rxml = getXMLFromQuery(tags, required)
  except DBAPIError:
      return Response("Error in DB", content_type='text/plain', status_int=500)

  return Response(rxml, content_type='text/xml', charset='utf8')
但是如果我通过Ajax执行相同的请求,我会得到:

XMLHttpRequest cannot load http://172.26.16.28:6543/metaschema/1/xml. Origin http://localhost is not allowed by Access-Control-Allow-Origin.
我需要做什么才能允许金字塔中的ajax请求

谢谢,
Carlos

本地主机和172.26.16.28是不同的域,大多数浏览器不允许AJAX请求。关于这个主题和可能的解决方案,您可以在这里找到:.

本地主机和172.26.16.28是不同的域,大多数浏览器不允许AJAX请求。更多关于这个主题和可能的解决方案,您可以在这里找到:。

感谢Alexander的解释

为了在金字塔中解决这个问题,我在代码中修改了这个

resp = Response(rxml, content_type='text/xml', charset='utf8')
resp.headerlist.append(('Access-Control-Allow-Origin', '*')) #Add the access control
return resp

谢谢亚历山大的解释

为了在金字塔中解决这个问题,我在代码中修改了这个

resp = Response(rxml, content_type='text/xml', charset='utf8')
resp.headerlist.append(('Access-Control-Allow-Origin', '*')) #Add the access control
return resp