Fórumok

Issue with AJAX call in Liferay Spring portlet

thumbnail
Subhasis Roy, módosítva 9 év-val korábban

Issue with AJAX call in Liferay Spring portlet

Expert Bejegyzések: 275 Csatlakozás dátuma: 2012.01.20. Legújabb bejegyzések
Hi,

Facing some issue with AJAX call. Please find my code snippet below.

JSP code:

function loadMyInfo(){
	$.ajax({
		
	    url : '<portlet:resourceurl id="getMyDataList" />',
	    type: 'POST',
	    dataType:'text',
	    contentType: "application/x-www-form-urlencoded; charset=utf-8",
	    data : formData,
	    success: function(data, textStatus, jqXHR){                                                                         
	                   // showSuccessResponse(data);
	                    
	    },                                             
	    error: function (jqXHR, textStatus, errorThrown){
	                    
	                  //  showErrorResponse();
	    } 
	});         
}



Controller Code:
@ResourceMapping("getMyDataList")
    public void getMyData(ResourceRequest request, Model model,ResourceResponse response, Locale locale, PortletSession session) throws Exception {
		
	System.out.print("Calling this method for AJAX Call");
       ...logic for other operations....
	}


This is not working for me. Some how the ajax call is not working and no error is also coming up in console. Need some help on this.
thumbnail
David H Nebinger, módosítva 9 év-val korábban

RE: Issue with AJAX call in Liferay Spring portlet

Liferay Legend Bejegyzések: 14919 Csatlakozás dátuma: 2006.09.02. Legújabb bejegyzések
If I had to guess I'd say your URL is either not correct, not mapped to go to the method like you think, or not mapped to the POST protocol (and therefore not mapped to go where you think).
thumbnail
Thomas Berg, módosítva 9 év-val korábban

RE: Issue with AJAX call in Liferay Spring portlet

Regular Member Bejegyzések: 131 Csatlakozás dátuma: 2009.09.07. Legújabb bejegyzések
Have you tried setting

<requires-namespaced-parameters> to false in liferay-portlet.xml?
thumbnail
Subhasis Roy, módosítva 9 év-val korábban

RE: Issue with AJAX call in Liferay Spring portlet

Expert Bejegyzések: 275 Csatlakozás dátuma: 2012.01.20. Legújabb bejegyzések
Hi,

Its my mistake, as I forgot to include the jquery.min.js file in my jsp.
That's why my jQuery function is not getting called. Added the following line in the JSP file and it worked.

<script src="<%=renderRequest.getContextPath()%>/js/jquery-1.11.1.min.js"></script>
thumbnail
David H Nebinger, módosítva 9 év-val korábban

RE: Issue with AJAX call in Liferay Spring portlet

Liferay Legend Bejegyzések: 14919 Csatlakozás dátuma: 2006.09.02. Legújabb bejegyzések
Bad bad bad idea.

To include javascript in the portlet you either a) add it into the theme or b) add it via the liferay-portlet.xml.

But you never, ever use the script tag to pull it in.