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

前端 未结 2 1173
误落风尘
误落风尘 2020-11-30 16:11

I am using a Jquery Token Input plugin. I have tried to fetch the data from the database instead of local data. My web service returns the json result is wrapped in xml:

2条回答
  •  無奈伤痛
    2020-11-30 16:24

    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.

提交回复
热议问题