AJAX返回完整的JSP文件而不是返回值

时间:2017-02-02 14:53:05

标签: jquery ajax

我的AJAX代码如下:

$.ajax({
    type:"GET",
    url : "https://unpuckered-armament.000webhostapp.com/zyro/sandeep1.jsp",
    data : { search: 'test' },
    dataType: 'json',
    success : function(json) {
        alert(json.title);
    }
});

我在000webhostapp.com上托管了我的JSP文件,如下所示:

<%@page contentType="text/html; charset=UTF-8"%>
<%@page import="org.json.simple.JSONObject"%>
<%
    JSONObject json = new JSONObject();
    json.put("title", "TITLE_TEST");
    json.put("link", "LINK_TEST");
    out.print(json);
    out.flush();
%>

我也尝试过:

 <%
        out.print("{\"name\":\"John\"}");
  %>

我有以下问题:

  1. 在AJAX中不调用成功函数。

  2. 当我在Chrome网络中查看时,我看到我收到整个文件,状态= 200。 请指教。

  3. enter image description here

    enter image description here

1 个答案:

答案 0 :(得分:1)

只要我记得000webhost只支持php,你需要一台支持php的服务器来处理文件,而不是获取文件内容。您的请求就像您要求提供文本文件一样。