0

I am stuck in weird situation. I am using autocomplete of jquery. I have mapped my URL with but I am getting 404.

Now when I look at the console, my URL is showing like this:

myProject-dashboard-svc/organization/[object%20Object]

While my actual URL is like ../organization/suggestion below is my full jquery code

$(function() {
  $("#searchByText").autocomplete({
    source:function(request,response){
      $.get({
        url:"../organization/suggestion",
        dataType:"json",
        contentType: "application/json",
        data:{
          q:request.term
        },
        success:function(data){
          response(data);
        }
      })
    }
  })
});
<input type="text" id="searchByText" hidden="true" name="searchByText" placeholder="enter name" class="autoComplete">

Please let me know why URL is displayed like this.
By the way, I have checked in Chrome as well as in Mozilla and I have the jquery-ui-jQuery-autocomplete and jQuery plugins.

Louys Patrice Bessette
  • 33,375
  • 6
  • 36
  • 64
LowCool
  • 1,187
  • 5
  • 25
  • 51

2 Answers2

1

Try to send the data as a string instead of a json object.
;)

$(function() {
  $("#searchByText").autocomplete({
    source:function(request,response){
      $.get({
        url:"../organization/suggestion",
        dataType:"json",
        contentType: "application/json",
        data: {"q:" + JSON.stringify(request.term) },       // Look here!
        success:function(data){
          response(data);
        }
      })
    }
  })
});
Louys Patrice Bessette
  • 33,375
  • 6
  • 36
  • 64
0

You should checkout signature for get https://api.jquery.com/jquery.get/. If you want to use get you should do it like this

      $.get("../organization/suggestion", {"q":request.term},function(data){
      response(data);
      },"json");

Or you could replace $.get with $.ajax

Jovana
  • 350
  • 3
  • 9
  • I replaced it with ajax and it worked but I don;t understand what difference it makes? – LowCool May 26 '17 at 10:19
  • Signature of $.ajax function and $.get function are different. $ajax takes one Object that contains configuration, like you passed it {url:"...", "data":"...",...} and $.get receives configuration in separate parameters $.get(url, data, success function, datatype) – Jovana May 26 '17 at 10:23