200 Jquery服务器请求没有响应

时间:2017-08-26 04:09:33

标签: javascript jquery flask

我的目标是从渲染的html页面打印一个字符串。

我正在使用以下代码从网址中获取正文内容:

    var proxy = "http://myproxyname.pythonanywhere.com/response?userinput=google"

    $.ajax({
        url: proxy,
        dataType: 'text',
        success: function(data) {
            $('#display').text(data);
        }
    })
}

我正在使用这个,因为我正在使用的API需要Allow cross origin,实际上,我设置了一个小瓶子应用程序,为我完成这项工作。我能够打印一些我用这个函数测试的网址的html,所以它正在工作,但对于那个我正在使用它的200 OK但空响应。

有人可以解释为什么我没有收到html内容吗? Jquery有特殊参数吗?我应该在我的烧瓶应用中启用跨源吗?

我的最后一个问题是如何发出请求,但是告诉Javascript不要考虑标题?

更新

当我从控制台手动发出请求时,我收到了回复但无法在页面cause = other上打印出来。当我点击按钮发出请求时,它会抛出cause = JS并且内部没有响应。

更新2:

当我在控制台中收到有效回复时,我只在请求标题中看到此更改:

  

Pragma“no-cache”

     

Cache-Control“no-cache”

有一种方法可以直接将它添加到JS代码中吗?

更新3:

我的代理使用Python代码(Flask):

@app.route('/response')
def response():

    url = 'http://longstringurlapi.com'
    data = str(request.args.get( "userinput" , None ))
    jsoninput = json.dumps(data)

    r = requests.post(url ,data=jsoninput)
    response = r.text

    return render_template('results.html', response=response, data=data)


@app.route('/')
def home():
    return render_template('index.html')

0 个答案:

没有答案
相关问题