FOSRestBundle jsonp请求下载力

时间:2014-06-03 14:57:36

标签: php symfony jsonp fosrestbundle

我对fos_rest部分的配置:

fos_rest:
    serializer:
        serialize_null: true
    view:
        view_response_listener: force
        force_redirects:
            html: true
        formats:
            jsonp: true
            json: true
            xml: false
            rss: false
        templating_formats:
            html: false
        mime_types:
            json: ['application/json', 'application/x-json', 'application/vnd.example-com.foo+json']
            jsonp: ['application/jsonp']
            rss: 'application/rss+xml'
            jpg: 'image/jpeg'
            png: 'image/png'
        jsonp_handler:
            callback_param:       callback
    body_listener: true
    param_fetcher_listener: force
    allowed_methods_listener: true
    access_denied_listener:
        json: true
    format_listener:
        rules:
          - { path: '^/', priorities: ['jsonp','json', 'xml'], fallback_format: json, prefer_extension: true }
    routing_loader:
        default_format: ~
    exception:
        codes:
            'Symfony\Component\Routing\Exception\ResourceNotFoundException': 404
            'Doctrine\ORM\OptimisticLockException': HTTP_CONFLICT
        messages:
            'Symfony\Component\Routing\Exception\ResourceNotFoundException': true

当我尝试访问ie

http://10.0.0.10/users.jsonp?callback=call 

我的数据被迫下载而不显示。请求的数据是正确的。如何在浏览器中显示它?

2 个答案:

答案 0 :(得分:0)

将您的配置更改为:

fos_rest:
    ...
    view:
        ...
        jsonp_handler:
            callback_param: callback
            # add jsonp mime-type here
            # it's `application/javascript+jsonp` by default
            mime_type: application/javascript

答案 1 :(得分:0)

如果您只是想跟踪错误跟踪有效负载并且您正在使用* nix系统,则可以使用curl进行此类操作。尝试这样的事情:

curl -i -X GET http://10.0.0.10/users.jsonp?callback=call