Is it possible to change the Url which JQuery's JQueryUI Autocomplete generates?

后端 未结 1 1702
一整个雨季
一整个雨季 2021-01-14 00:23

I\'m using JQuery JQueryUI\'s AutoComplete code. It goes to my url i provide (to find the answers), but appends ?term= after the url.

<
相关标签:
1条回答
  • 2021-01-14 00:57

    You can use $.getJSON() yourself in the source option, for example:

    $(".autocomplete").autocomplete({ 
      source: function(req, resp) {
        $.getJSON("/myurl/" + encodeURIComponent(req.term), resp);
      }
    });
    

    Something similar happens when you give it a string, it sends the first parameter passed to the method as the object...which has a property term, by doing it manually you're just getting more control over your parameters. I'm also using encodeURIComponent() above to be safe when generating a url directly (e.g. spaces to +, etc.).

    0 讨论(0)
提交回复
热议问题