我无法获取 servlet 页面中的 POST 值?
我无法在 servlet 页面中获取 POST 值。我之前的问题与此问题相关。如何从 servlet 页面中的 ajax 请求获取数据?
我需要 servlet 页面中的 dataRequestObject 值。
var dataRequestObject= {};
dataRequestObject= {mark:Mark,subject:English,language:C language,author:john};
var dataRequestHeader= {};
dataRequestHeader= {Username:uname,Password:pword,Domain:domain,WindowsUser:windowsuser};
$.ajax({
type:'POST',
url:'http://localhost:8090/SampleServlet1/serv', //calling servlet
cache:false,
headers:dataRequestHeader,
data:JSON.stringify(dataRequestObject),
success:function(){ alert("Request Done");},
error:function(xhr,ajaxOptions){
alert(xhr.status + " :: " + xhr.statusText);
}
});
提前致谢。
I couldn't get the POST value in servlet page. my previous question related to this question.How to get the data from ajax request in servlet page?
I need dataRequestObject value in my servlet page.
var dataRequestObject= {};
dataRequestObject= {mark:Mark,subject:English,language:C language,author:john};
var dataRequestHeader= {};
dataRequestHeader= {Username:uname,Password:pword,Domain:domain,WindowsUser:windowsuser};
$.ajax({
type:'POST',
url:'http://localhost:8090/SampleServlet1/serv', //calling servlet
cache:false,
headers:dataRequestHeader,
data:JSON.stringify(dataRequestObject),
success:function(){ alert("Request Done");},
error:function(xhr,ajaxOptions){
alert(xhr.status + " :: " + xhr.statusText);
}
});
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不应该将其作为 JSON 字符串发送,而应作为 JS 对象发送。 JS 对象中存在的键以通常的方式更改
通过
和访问 servlet 中的值
请注意,您的 servlet 需要在同一域中运行,否则您将点击 同源政策。如果它实际上在同一个域上运行,那么我不会在 JS 代码中对该域进行硬编码,因为这会使您的代码完全不可移植。所以
用
or代替。
也
You shouldn't send it as JSON string, but just as JS object. Change
by
and access the values in the servlet the usual way by the keys as present in JS object
Note that your servlet needs to run in the same domain, otherwise you hit the Same Origin Policy. If it's actually running on the same domain, then I would not hardcode the domain in the JS code since it makes your code totally unportable. So replace
by
or
as well.
您可以尝试以下解决方案:
http://developer.yahoo.com/javascript/howto-proxy .html
Can you try this solution:
http://developer.yahoo.com/javascript/howto-proxy.html