如何发送JSON数据的形式jQuery的? [英] How to send json data form jQuery?
问题描述
我想送JSON字符串
var json = {"city":value1, "country":value2};
$.ajax({
url : url,
data : json,
dataType : 'json',
success : function(response) {
alert(response);
}
})
在网址
来我做的AJAX调用我没有得到如何得到这个字符串值有哪些?我应该怎么使用的request.getParameter
?什么应该是参数的值?
In the URL
to which I make ajax call I am not getting how to get this string value there? What should I use request.getParameter
? What should be the value in the parameter?
推荐答案
这可能是一个坏主意,但完成这项工作。谢谢大家分享您的想法已经很难发送数据。只见由@baadshah所有的参考答案,但是,我无法实现单个之一。 :(我重新分析了问题。
This might be a bad idea but has done the job. Thanks everyone for sharing your thoughts had hard time sending data. I saw all the suggested answers by @baadshah but, I couldn't implement a single one. :(. I reanalyzed the problem.
我的问题是我不能检索服务器端页面的 JSON
数据,其中,因为我是能够访问其他元素。我的HTML页面有其中之一
My problem is I can't retrieve the JSON
data in the server side page where as I was able to access other elements. My HTML page had one of these
<input type = "text" name = "fname" class = "imp"/>
在我的JSP页面中,我可以用
In my JSP page I could use
String fname = request.getParameter("fname");
一直停留时间超过两个小时,感到沮丧我想另一种方式之后。这是我找到了解决办法。这个问题将如果我能俱乐部 JSON
字符串具有有效名称的任何输入的标签来解决。下一刻我在脚本标签加入这一行
After being stuck for more than couple of hours and getting frustrated I thought for another way. This is the solution I found. This problem would be solved if I can club the JSON
string with any input tag with a valid name. The next moment I added this line in script tag
$('input[name=hide]').val(json);
var dataToBeSent = $("form#hidden").serialize();
在HTML部分我添加以下代码片段。
In the HTML part I added following snippet.
<form name="hidden" id="hidden">
<input type="hidden" name="hide"/>
</form>
这解决了我的问题。这可能不是最好的办法周围,但它做的工作。
This solved my problem. This might not be the best way around but it did the job.
这篇关于如何发送JSON数据的形式jQuery的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!