Skip to Content
avatar image
Former Member

Ajax search for MII 12.2

Hi guys,

I am writing to ask you for some assistance. I have to implement an Ajax search for an input box in MII 12.2. It should suggest possible entry values when I type in, let's say, 2 characters.

My IRPT file head section:

<head>

<meta http-equiv="Content-Type" content="text/html;charset=utf-8">

<title>Ajax Test Project</title>

<script src="http://code.jquery.com/jquery-1.9.1.js"></script>

<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>

<script type="text/javascript" src="javascript/ms.js"></script>

<script type="text/javascript" src="javascript/ajaxfunc.js"></script>

<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css"/>

<link rel="stylesheet" type="text/css" href="css/ms.css"/>

</head>

The section with the input box (as it can be seen, it lies within a table, the table is called InputTable, has been referenced in my ms.css):

<td><input class="text" type="text" id="Workcenter2" name="Workcenter2" tabindex="5" height="18px"/></td>

This is my Javascript function:

$("#Workcenter2").autocomplete({

autoFocus: true,

source: function (request, response) {

  $.ajax({

   url: "/XMII/Runner?Transaction=YDM/AjaxProject/Dialogs/Logic/WorkCenterValuesTrx&TRXID=1&OutputParameter=Results",

   type: "GET",

   dataType: "xml",

   data: {

    maxRows: 10,

    Workcenter2: request.term

   },

   success: function (data) {

    response($.map(data, function(item,key) {

     return {

      label: key,

      value: item

     }

    }))

   },

   error: function () {

    alert("Due to an unexpected error, we were unable to load data.");

   },

   messages: {

    noResults: '',

    results: function() {}

   }

  });

},

minLength: 2

});

I can access the transaction from the browser (for the sake of testing), it displays all possible entries in an XML format. When I run the code in MII I have no compilation errors, but still no suggestions when I type in two letters. Last, I add the relevant part of my CSS:

/* loading - the AJAX indicator */
table.InputTable td .ui-autocomplete-loading
{
background: white url("../images/loader.gif") right center no-repeat;
}

table.InputTable td .autocomplete-suggestions
{
border: 1px solid #999;
background: #fff;
cursor: default;
overflow: auto;
}

table.InputTable td .autocomplete-suggestion
{
padding: 10px 5px;
font-size: 1.2em;
white-space: nowrap;
overflow: hidden;
}

table.InputTable td .autocomplete-selected
{
background: #f0f0f0;
}

table.InputTable td .text
{
display: block;
}

I am not really experienced in Ajax, so any suggestion from your side will be appreciated.

Best,

Yavor

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    avatar image
    Former Member
    Jan 16, 2014 at 10:52 AM

    For the Url passing please try as below it works, I had a same problem where transaction used to give xml fine on browser and not from the code of ajax call.

    Below is two option to help you, The first when u want want to directly pass the values to Trx call without any variable.(Dont use quotes it wont work)

    1. var urlPath="http://"+location.host+"/XMII/Runner?Transaction=YDM/AjaxProject/Dialogs/Logic/WorkCenterValuesTrx&TRXID=1&OutputParameter=Results&Content-Type=text/xml";

        $.ajax({

             type : "POST",

             url : urlPath,

                    datatype : "xml",

              cache: false,

             async: false,

             beforeSend: function()

             {

                

             },

             error: function()

             {

                alert('Error');

             },

    2. var urlPath="http://"+location.host+"/XMII/Runner?Transaction=YDM/AjaxProject/Dialogs/Logic/WorkCenterValuesTrx&Var1="+Val1+"&Var2="+Val2+"&OutputParameter=Results&Content-Type=text/xml";

    The above second option is , you are assigning the variable values to transaction parameters.

    Hope it works. Good Luck

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member christian libich

      I actually did solve the issue about two hours ago. Christian was right, it was namely a badly constructed Javascript function. However, I was also missing a proper parsing of the XML data I receive from the transaction. Now that both have been implemented I can use the suggestion box. There is still a small bug for me to take care of as the autocomplete works perfectly in Mozilla and not quite as expected in Internet Explorer 8, but this should mainly concern my CSS entries.

      Thank you, Christian and Padma for the support!