Note that there are some explanatory texts on larger screens.

plurals
  1. POgrails: display new web page via an ajax call
    primarykey
    data
    text
    <p>I've had a look at a number of posts and none seem to handle this problem.</p> <p>I am trying to send data from a javascript via an ajax call and then get that data into a grails controller/action at server level to process and then to display that web page. The data gets transferred okay but the target web page fails to replace the current web page.</p> <p>Here is the ajax call that sends the data to the action successfully:</p> <pre><code> $.ajax({ type: "POST", url: "createVideopNm", dataType: "json", contentType: "application/json", asynch: false, processData: false, data: vidData //data: vidAudioId, // data: { name: "Mike", location: "UK" }, }) .done(function(msg, status, error) { alert( "getJsVCoords Done: data SAVED - Sys status: " + status + "\n" + " Error: " + error + "\n" + " responseText: " + msg.responseText ) }) .error(function(msg, status, error) { alert( "getJsVCoords Error: Data NOT Saved -1- Sys status: " + status + "\n" + " Error: " + error + "\n" + " responseText: " + msg.responseText ) }) </code></pre> <p>Here is the controller action which is definitely run through from the ajax call:</p> <pre><code> def createVideopNm(Integer max) { if(request.method == 'GET') { log.debug(" createVideopNm - GET ") } else if(request.method == 'POST') { // POST called from javascript functrionsendVidData in pNm log.debug(" createVideopNm - POST -1-") def jsonObject = request.JSON log.debug(" createVideopNm - POST -2-" + jsonObject.xCoord) render ( ['X': jsonObject.xCoord , 'Y': jsonObject.yCoord , 'P' : jsonObject.picId, 'A' : jsonObject.audioId] as JSON) log.debug(" createVideopNm - POST -3-") } def workVideo= prepVideopNm() flash.message = "createVideopNm workVideo nm: ${workVideo}" log.debug(" createVideopNm - -4-") params.max = Math.min(max ?: 10, 100) log.debug(" createVideopNm - -5-") [workVideo: workVideo] log.debug(" createVideopNm - -6-") return true } </code></pre> <p>As you can see I have a GET and a POST path through the action - if I simply bring up the page by typing in the URL in the browser address field it works fine. But if I invoke the action through the ajax call it does not appear - all logging indicates every thing is fine. For example, the Chrome web diagnostic tool Console has a message - "XHR finished loading: '<em>url name</em>'</p> <p>Comparing the grails log file for both the GET and the POST/ajax operations there are some additional grail log messagesfor the GET which reflects the fact it does correctly display the web page:</p> <pre><code>2013-05-16 20:05:42,104 [http-bio-9000-exec-8] DEBUG homevu1.VideosController - createVideopNm - -4- 2013-05-16 20:05:42,104 [http-bio-9000-exec-8] DEBUG homevu1.VideosController - createVideopNm - -5- 2013-05-16 20:05:42,104 [http-bio-9000-exec-8] DEBUG homevu1.VideosController - createVideopNm - -6- 2013-05-16 20:05:42,215 [http-bio-9000-exec-8] DEBUG resource.ResourceTagLib - resolveResourceAndURI: [dir:images, file:favicon.ico] 2013-05-16 20:05:42,216 [http-bio-9000-exec-8] DEBUG resource.ResourceTagLib - resolveResourceAndURI: [dir:images, file:apple-touch-icon.png] 2013-05-16 20:05:42,217 [http-bio-9000-exec-8] DEBUG resource.ResourceTagLib - resolveResourceAndURI: [dir:images, file:apple-touch-icon-retina.png] 2013-05-16 20:05:42,218 [http-bio-9000-exec-8] DEBUG resource.ResourceTagLib - resolveResourceAndURI: [dir:css, file:main.css] 2013-05-16 20:05:42,219 [http-bio-9000-exec-8] DEBUG resource.ResourceTagLib - resolveResourceAndURI: [dir:css, file:mobile.css] 2013-05-16 20:05:42,219 [http-bio-9000-exec-8] DEBUG resource.ResourceTagLib - laying out resources for request org.apache.catalina.connector.RequestFacade@275a7e94: [:] 2013-05-16 20:05:42,220 [http-bio-9000-exec-8] DEBUG resource.ResourceTagLib - Rendering resources for disposition [head] 2013-05-16 20:05:42,220 [http-bio-9000-exec-8] DEBUG resource.ResourceTagLib - Rendering resources, modules in tracker: null 2013-05-16 20:05:42,220 [http-bio-9000-exec-8] DEBUG resource.ResourceTagLib - Rendering resources, modules needed: [] 2013-05-16 20:05:42,220 [http-bio-9000-exec-8] DEBUG resource.ResourceTagLib - Rendering non-deferred resources, modules: []... 2013-05-16 20:05:42,220 [http-bio-9000-exec-8] DEBUG resource.ResourceTagLib - Rendering page fragments for disposition: head 2013-05-16 20:05:42,220 [http-bio-9000-exec-8] DEBUG resource.ResourceTagLib - Removing outstanding request disposition: head 2013-05-16 20:05:42,221 [http-bio-9000-exec-8] DEBUG resource.ResourceTagLib - resolveResourceAndURI: [dir:HomeVu1/skin, file:HomeVu.jpg, absolute:false] </code></pre> <p>Whereas the POST via ajax operation the logging simply stops after the 'createVideopNm - -6-' message.</p> <p>What is different in the behavior when an grails action is invoked via an ajax call as opposed to directly by typing in the url address into a browser?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload