发布于 2009-11-17 22:34:43
我认为数据需要是一个字符串。对象被转换为查询字符串,这就是您在这里看到的。
可以使用JSON.stringify(obj)
方法将对象转换为字符串。JSON对象的代码可以从https://github.com/douglascrockford/JSON-js/blob/master/json2.js获得。
或者,只需将用于创建对象的代码作为文字字符串传递,但我认为这只是一个示例,您将希望对已经创建的对象进行编码。
发布于 2011-07-26 17:45:45
如果必须在应用程序中始终发送JSON,那么只需在初始化中的某个位置执行此操作,然后使用示例中的默认$.ajax
调用,它将始终序列化为JSON字符串,而不是Ajax默认查询字符串。
这里我使用了上面提到的JSON对象:
$.ajaxSetup({
contentType : 'application/json',
processData : false
});
$.ajaxPrefilter( function( options, originalOptions, jqXHR ) {
if (options.data){
options.data=JSON.stringify(options.data);
}
});
发布于 2012-07-05 21:12:00
//url: this is a reference to the XML, where you need to define the mapping.
//<entry key="/getEmpDetails/transEfileGenerate.app">
//<bean class="com.adp.ems.framework.spring.MappingItem" p:delegate-ref="efilePageDelegate"
//p:action="passJSONObjectAndGetWebServiceOutput" />
//str1 is the input JSON that you need to pass... Ajax will automatically take care to get the response.
//</entry>
var kw = {
url : "getEmpDetails/transEfileGenerate.app",
timeout : 30000,
handleAs : "json",
sync: false,
putData : str1,
headers: { "Content-Type": "application/json"},
load : function(result) {
},
https://stackoverflow.com/questions/1749272
复制相似问题