0

While passing parameter in grails with Ajax ,parameter with special character (&) splits and not pass completely as i required to pass to the controller.Here in department, there is drop down list of department with special character.when i click the department it split and only before the special character it passes .but i requires all list name with special character.

var parameter = "searchPatientString="+searchPatientString+"&type="+type+"                 &searchPatientId="+searchPatientId+"&department="+department;
                 $.ajax( {
                url: "${createLink(controller: 'allPatient', action:'patientDeptList')}",
                type : 'post',
                data : parameter,
                success : function( resp ) {
                    if(resp=="noValue"){
                        $('#msg').show();
                    }
lukelazarovic
  • 1,510
  • 11
  • 19
amr9349
  • 15
  • 1
  • 1
  • 8

2 Answers2

0

You need to encode the ampersand character '&' in the query string. Code for ampersand is '%26' - see escaping ampersand in url

But you can have problems also with other characters in query string values so the best way is not to concatenate query string manually but rather do it like proposed here: Ampersand (&) character inside a value of jQuery AJAX request data option

Community
  • 1
  • 1
lukelazarovic
  • 1,510
  • 11
  • 19
0
var parameter = "searchPatientString="+searchPatientString+"
                 &type="+type+"&searchPatientId="+searchPatientId+"
                 &department="+department;

You need to change this as follow :

 data : parameter, instead of this one user as follow

 data : { searchPatientString:"${searchPatientString}",
           type:"${type}",searchPatientId:"${searchPatientId}",
           department:"${department}"}

It will work seamlessly , you shouldnt care about specail characters. And ,also note that

ex. ${searchPatientString} all mentioned like ${} should be ur grails varibles,

Develop4Life
  • 7,581
  • 8
  • 58
  • 76