What should be the correct response from web service to display the Jquery token input results?

依然范特西╮ 提交于 2019-11-27 05:42:03
Mark

You need to make sure that your request is a POST request. Not a get request. See this answer to find out more about why: How to let an ASMX file output JSON

I would assume that the code for the plugin isn't setting the content-type for ajax requests to JSON, so you could do it yourself before the service call with $.ajaxSetup ie:

$.ajaxSetup({
  contentType: "application/json; charset=utf-8"
});

UPDATE: Apparently asmx services sometimes have issues with the 'charset=utf-8' portion, so if that doesn't work you could try just 'application/json'

UPDATE 2:

I don't think it's the contentType causing the issue, use the following to force a POST for ajax requests and see if this fixes it:

$.ajaxSetup({
  type: "POST", contentType: "application/json; charset=utf-8"
});

UPDATE 3:

There is a default setting inside the plugin you're using that can change the requests from GET to POST. See here on it's GitHub repo: jquery.tokeninput.js

and in your copy of the js file in the project, change the line:

var DEFAULT_SETTINGS = {
    // Search settings
    method: "GET",

to

var DEFAULT_SETTINGS = {
    // Search settings
    method: "POST",

I also assume that the plugin constructs the query in a way that ignores the global jquery ajax settings anyway, so you shouldn't need to include my earlier snippets anymore.

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