Results 1 to 3 of 3
- 07-19-2010, 02:21 PM #1
Member
- Join Date
- Jul 2010
- Posts
- 2
- Rep Power
- 0
Problem with Axis2 and JSON when calling web service in javascript
Hi all. I have a problem when calling Axis2 web service from javascript. I want to use it with JSON format. So as Axis2 has JSON support, I have set both messageFormatter and messageBuilder like it is in documentation. Also I am using DynamicResponseHandler.
Now, when I call it from javascript using GET method, it's working, but when I change it to POST, it not works. I am new to this, so I don't know, where is the problem. In Axis2 docs there is written that default is POST, so it should works, but for me not. Response never come back from server, and server is processing something till I stop him.
Here is my service class
package com.yms.tis.json;
import org.apache.axis2.context.OperationContext;
import org.apache.axis2.context.ServiceContext;
public class JSONService {
public void init(ServiceContext serviceContext) {
}
public void destroy(ServiceContext serviceContext) {
}
public void setOperationContext(OperationContext operationContext) {
}
public MenuItem[] getMenu() {
MenuItem[] menu = new MenuItem[3];
for (int i = 0; i < menu.length; i++) {
MenuItem menuItem = new MenuItem(i, "menuitem" + i,
"<div>toto je xxx content</div>");
menu[i] = menuItem;
}
return menu;
}
}
Here is the java script code:
this is working
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script src="javascript/jquery-1.4.2.min.js" type="text/javascript"></script>
</head>
<body>
RESULT:<br />
<div id="result_panel">
</div>
</body>
<script type="text/javascript">
$.ajax({
url: 'services/JSONService/getMenu?response=application/json',
dataType: "json",
type : "GET",
success: function (xxx) {
$("#result_panel").html(xxx.getMenuResponse.retu rn[0].content); },
error: function (html) {
alert('ERROR');
}
});
</script>
</html>
and this not:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script src="javascript/jquery-1.4.2.min.js" type="text/javascript"></script>
</head>
<body>
RESULT:<br />
<div id="result_panel">
</div>
</body>
<script type="text/javascript">
$.ajax({
url: 'services/JSONService/getMenu',
dataType: "json",
contentType: "application/json; charset=utf-8",
type : "POST",
success: function(msg) {
$("#ReturnMessage").html(msg.d);
},
error: function (html) {
alert('ERROR');
}
});
</script>
</html>
Can you tell me what I've done wrong, please?
Thanks a lot for any help.
- 01-18-2011, 09:45 AM #2
Member
- Join Date
- Jan 2011
- Posts
- 1
- Rep Power
- 0
Same problem
Hi Pista,
did you get it working?
I'm trying to connect to an axis2 json WS with dynamic response handler from android emulator. But if i set the contenType to "application/json" i will get no response from axis.
- 01-18-2011, 10:19 AM #3
Member
- Join Date
- Jul 2010
- Posts
- 2
- Rep Power
- 0
'traditional' parameter
Yes, the problem was that parameter traditional = true was missing for POST type, so it should looks like :
var _json_request = function (method, data, callback, allowParalel) {
var self = this;
var url = 'services/TestService/' + method + '?response=application/json',
responseElement = method + 'Response';
var newRequest = $.ajax({
type: 'POST',
url: url,
dataType: 'json',
data: data,
timeout: 10000,
traditional: true,
success: function (response) {
$('#result_panel').html(response[responseElement]['return']);
},
error: function (response) {
alert('Chyba v komunikácii so serverom!');
}
});
Hope this helps you.
Similar Threads
-
JSON Lib: json-lib-1.0-jdk13.jar
By Raghuraman K in forum Advanced JavaReplies: 3Last Post: 05-13-2010, 10:00 AM -
axis2 thread
By sheky in forum Java SoftwareReplies: 2Last Post: 01-06-2010, 10:38 AM -
JSON from javascript to java servlet
By boss-tech in forum Java ServletReplies: 1Last Post: 09-18-2009, 08:27 AM -
[SOLVED] calling javascript from applet method
By shwein in forum Java AppletsReplies: 5Last Post: 11-01-2008, 04:45 PM -
[SOLVED] calling javascript from applet
By shwein in forum Java AppletsReplies: 5Last Post: 10-31-2008, 11:45 PM


LinkBack URL
About LinkBacks

Bookmarks