I have just created an AJAX request in velocity template and able to get request at .java file as below:
var url ="PlanIssuesAction!IssuesPlanning.jspa"; jQuery.post(url,myJSONObject,function(result){ alert('success');}).done(function(){ alert("in done");}).fail(function(){ alert("error");}).always(function(){ alert("finished");});
On the server side, in doIssuesPlanning
method, able to get call and insert the posted data.
Now I need to return the result data to the client side back at jquery "Result" parameter. How can I achieve this? Currently, in "Result" object shows all HTML text.
Thank you.
ignore my previous answers and try something like this
set the message in your java file as
addErrorMessage("Success executed result appear");
add something like this in ur velocity file
#foreach ($error in $action.getErrorMessages()) <li>$error</li> #end #foreach ($error in $action.errors) <li>$error</li> #end
Do i have to add as below at server side ?:
@POST @Path("/save") @Produces("application/json") //@Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) public String SaveIssuesPlanning() { addErrorMessage("Success executed result appear"); //added newly logger.info("in saveissuesplanning method"); logger.info(end + start + issues); logger.info("end saveissueplanning"); return "result success found"; }
At client side, in error event have to add as below ?
error: function(resp, status, xhr){ /*added new block */ #foreach ($error in $action.getErrorMessages()) <li>$error</li> #end #foreach ($error in $action.errors) <li>$error</li> #end /* end added new block */ alert('in error json'); alert("Error: " + resp.e); jQuery("#errorPost").html("Error: " + resp.e + " - STATUS: " + xhr.status + " " + xhr.statusText);
Please correct me... and also let me know , how should i keep URL for calling method at server side.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
use your url as
var url ="PlanIssuesAction!IssuesPlanning.jspa"; jQuery.post(url,myJSONObject,function(result){ alert('success');}).done(function(){ alert("in done");}).fail(function(){ alert("error");}).always(function(){ alert("finished");});
as you said On the server side, in doIssuesPlanning
method, able to get call and insert the posted data and after that addthis method.
addErrorMessage(
"Success executed result appear"
);
#foreach ($error in $action.getErrorMessages())
<li>$error</li>
#end
#foreach ($error in $action.errors)
<li>$error</li>
#end
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
in vm file, error event , alert shows me "undefined",
alert("Error: " + resp.e); alert("Error: " + xhr.statusText); alert("Error: " + xhr.status);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
ok. i have undo as above.
and added addErrorMessage(
"Success executed result appear"
); line at server side at end of the function as below:
public String doIssuesPlanning() { logger.info("in PlanIssuesAction"); ... addErrorMessage("Success executed result appear"); return getRedirect("PlanIssuesAction!default.jspa"); }
In velocity template,
added
JQuery.post(url,myJSONObject,function(result) { alert(result); }) .done(function(result) { alert("second success" + result); }) .fail(function() { alert("error event in JQUERY AJAX"); #foreach ($error in $action.getErrorMessages()) <li>$error</li> alert("error as " + $error); #end #foreach ($error in $action.errors) alert("error is " + $error); <li>$error</li> #end }) .always(function() { alert("finished"); selectedVal = ''; } );
No any effect looks like. when add alert for " $action.getErrorMessages()" then shows empty message box.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
On server side, if i keep as below: then, on client side, .done- alert (result) messagebox will show me whole HTML page's code and no error raise. But problem remains there as it is , how to send result data to client side.
//addErrorMessage("Success executed result appear"); //if uncomment then, ajax event catch in error. return getRedirect("PlanIssuesAction!default.jspa");
Alternate try,
If i update above stuff as below: then, client side, ajax event will catch at - .Fail and error raised instead of .done result capature.
//addErrorMessage("Success executed result appear"); //commented // return getRedirect("PlanIssuesAction!default.jspa"); //commented return "final data result from AJAX call - success"; //result data to capture at client side.
Another :
if it could be not be possible straightly as it looks, then, instead of JiraWebActionSupport java file, do you think it could achievable through HttpServlet?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
this is what i am using at server side
@GET @AnonymousAllowed @Path("/test") @Produces("application/json") public Response getMajorSystems(@QueryParam("ProjectId") String projectId) { JSONObject json = new JSONObject(); //add your logic here json.append("status","Sucess"); return Response.ok(json.toString()).build(); }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here, at server side, i have been using "JiraWebActionSupport" and not "HttpServlet", so, unable to get "Response" object ., is there any alternative to use ?
Also, please let me know, how this particular "getMajorSystems" method will be called from client side AJAX url ?, is it like - var url = "PlanIssuesAction!IssuesPlanning.jspa"; (keep - doIssuesPlanning() method) ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
Thanks for your comments.
Based on your comments, i have created below stuff but , it every time, goes to error only and unable to call server sider method. Can you please look at below and correct me.
client side in velocity template:
var url ="http://localhost:2990/jira/secure/PlanIssuesAction!default.jspa/SaveIssuesPlanning/save"; //(also tried below possibilities of url but not worked), //var url ="http://localhost:2990/jira/secure/PlanIssuesAction!default.jspa/SaveIssuesPlanning"; //var url ="http://localhost:2990/jira/secure/PlanIssuesAction!default.jspa/save"; jQuery.ajax({ type: "POST", url: url, contentType: "application/json", dataType: "json", data: "SaveRequestingData", success: function (resp, status, xhr) { alert('in success JSON'); var msg = "result is: " + resp.result + ", Start: " + resp.start + ", End: " + resp.end + ", issues: " + resp.issues; alert(msg); jQuery("#successPost").html(msg + " - STATUS: " + xhr.status + " " + xhr.statusText); }, error: function(resp, status, xhr){ alert('in error json'); alert("Error: " + resp.e); jQuery("#errorPost").html("Error: " + resp.e + " - STATUS: " + xhr.status + " " + xhr.statusText); } });
at server side, java class which is extended for "JiraWebActionSupport" package used for webwork.
@POST @Path("/save") @Produces("application/json") public String SaveIssuesPlanning(String pi) { logger.info("in saveissuesplanning method"); logger.info(pi); logger.info("end saveissueplanning"); return "result success found"; }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
is request going to SaveIssuesPlanning method?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No, does not go to "SaveIssuesPlanning "method so, unable to get log.
I am using - JiraWebActionSupport extend class as it is webwork module.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
for your reference $.ajax({ url: url, data: {term : request.term}, dataType: "json", contentType: "application/json; charset=utf-8", dataFilter: function(data) { return data; }, success: function (data) { var results = $.map(data, function(item){ return { value: item.value, id: item.id }}); cache[request.term] = results; response(results); } });
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for your comments.
I able to make AJAQ request and posted data get inserted, Now, i want to send result value fail/success to client side at "success" event result parameters (here above example function(data) ). How can we send result from velocity template - .JAVA file (JiraWebActionSupport).. any way to write result, like - response.write(...) in .JAVA file (JiraWebActionSupport).
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Below is the stuff which is used at server side .java file.
here, System.out.println is used to send the result to client side but it does not work. How it could be achivable ?
publicString doIssuesPlanning(){**System.out.println("Success executed result appear");//i want this value to be retrieval at client side but //not working.**}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.