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

不羁的心 提交于 2019-12-01 04:24:24

问题


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

I'm trying to get the following url intead ...

/myurl/<term / search query>

eg.

/myurl/abcd
/myurl/hello+world

etc...

is it possible to do this?

Otherwise, it is possible to rename the query parameter term to something else, .. like query to q, etc?


回答1:


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.).



来源:https://stackoverflow.com/questions/3694551/is-it-possible-to-change-the-url-which-jquerys-jqueryui-autocomplete-generates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!