Extjs 使用JSONP getting“发出跨域请求;意外标识符“;
以下是我正在尝试的: 在客户端:Extjs 使用JSONP getting“发出跨域请求;意外标识符“;,extjs,extjs4,jsonp,Extjs,Extjs4,Jsonp,以下是我正在尝试的: 在客户端: Ext.data.JsonP.request({ url: "http://172.24.87.38:9090/DynamicWeb/hello-world", params: { }, callback: function (result) { console.log(result); if (response.success === true) { Ext.Msg.ale
Ext.data.JsonP.request({
url: "http://172.24.87.38:9090/DynamicWeb/hello-world",
params: {
},
callback: function (result) {
console.log(result);
if (response.success === true) {
Ext.Msg.alert('Link Shortened', response.result, Ext.emptyFn);
} else {
Ext.Msg.alert('Error', response.result, Ext.emptyFn);
}
}
});
在其他域(服务器端):
Ext.data.JsonP.request({
url: "http://172.24.87.38:9090/DynamicWeb/hello-world",
params: {
},
callback: function (result) {
console.log(result);
if (response.success === true) {
Ext.Msg.alert('Link Shortened', response.result, Ext.emptyFn);
} else {
Ext.Msg.alert('Error', response.result, Ext.emptyFn);
}
}
});
公共类HelloWorldServlet扩展了HttpServlet{
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
/*resp.setContentType("text/html");
PrintWriter out = resp.getWriter();
out.print("Hello World from Servlet");
out.flush();
out.close();*/
boolean jsonP=false;
String cd=req.getParameter("callback");
String n= "{data:Hello World from Servlet}";
if (cd!=null) {
jsonP=true;
resp.setContentType("text/javascript");
} else {
resp.setContentType("application/x-json");
}
Writer out=resp.getWriter();
out.write(n);
}
}
我收到的错误:
Ext.data.JsonP.request({
url: "http://172.24.87.38:9090/DynamicWeb/hello-world",
params: {
},
callback: function (result) {
console.log(result);
if (response.success === true) {
Ext.Msg.alert('Link Shortened', response.result, Ext.emptyFn);
} else {
Ext.Msg.alert('Error', response.result, Ext.emptyFn);
}
}
});
未捕获的语法错误:意外的标识符
{data:Hello World from Servlet}
我没有错。请帮我解决这个问题。任何帮助都将不胜感激。谢谢
此外,您返回的json似乎是错误的,请尝试:
callback += "({\"success\":true, \"msj\":" + "\"" + "Exitoooo!" + "\" });"; // where callback is the parameter sent via url
可能重复编辑到:“{'data':'Hello World from Servlet}”;但获取错误“意外标记:”@守护进程值可以是双引号中的字符串、数字、true或false或null、对象或数组: