Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4012972
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:18:48+00:00 2026-05-20T09:18:48+00:00

$.ajax({ type: POST, url: /webservices/AutoSuggestWebService.asmx/GetSuggestedRestaurants, data: {‘prefixText’: ‘ + $(‘#ctl00_ctl00_cplMPBody_txtSearch’).val() + ‘}, contentType: application/json;

  • 0
$.ajax({
        type: "POST",
        url: "/webservices/AutoSuggestWebService.asmx/GetSuggestedRestaurants",
        data: "{'prefixText': '" + $('#ctl00_ctl00_cplMPBody_txtSearch').val() + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            data = msg.d;
            alert(msg.d)
            $("#ctl00_ctl00_cplMPBody_txtSearch").autocomplete(data);
        }
    })

where data is

["some text","another some textz","huh just text"]

WS:

[WebMethod]
        public string GetSuggestedRestaurants(object prefixText)
        {
            JavaScriptSerializer js = new JavaScriptSerializer();
            string json = js.Serialize(new RestaurantSearchHelper(DaoFactory).GetSearchSuggest(prefixText.ToString(), PageBase.CurrentCountry));
        }

but if i search by word “so” i don’t get anything.

If ws return

[WebMethod]
        public string GetSuggestedRestaurants(object prefixText)
        {
            return  "Aeroplane dkhashd Apple Ambulance Border Crops Desalination Elephants  Parrot ";
        }

and js looks like

data = msg.d.split(" ");
alert(data)

then data looks like

Aeroplane,dkhashd,Apple,Ambulance,Border,Crops,Desalination,Elephants,Parrot

and autosuggest work. What is worng with first json if data is

["some text","another some textz","huh just text"]
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T09:18:49+00:00Added an answer on May 20, 2026 at 9:18 am

    Your first error is that the text

    {'prefixText': 'bla bla'}
    

    is NOT valid JSON string. It could be correct object initializer in JavaScript, but it is wrong encoded JSON corresponds to http://www.json.org/ and RFC4627. Correct JSON string will be

    {"prefixText": "bla bla"}
    

    or the following

    data: '{"prefixText": "' + $('#ctl00_ctl00_cplMPBody_txtSearch').val() + '"}'
    

    in your case (with some small possible problems if $('#ctl00_ctl00_cplMPBody_txtSearch').val() has " or \ characters inside). I recommend you http://www.jsonlint.com/ site where you can validate any JSON data.

    The next problem is on the server side. The ASMX web method should be like the following

    [WebMethod]
    [ScriptMethod (ResponseFormat = ResponseFormat.Json)]
    public List<string> GetSuggestedRestaurants(string prefixText) {
        return new RestaurantSearchHelper(DaoFactory).GetSearchSuggest(
                       prefixText,
                       PageBase.CurrentCountry);
    }
    

    and the corresponding class should has [ScriptService] attribute.

    I recommend you to use JSON.stringify method:

    data: JSON.stringify({ prefixText: $('#ctl00_ctl00_cplMPBody_txtSearch').val() })
    

    instead of manual JSON serialization. See details in my other answer which include link to the working demo project.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

$.ajax({ type: POST, url: WebService.asmx/AddVisitor, data: {'fname':'dave', 'lname':'ward'}, contentType: application/json; charset=utf-8, dataType: json });
.ajax({ type: 'POST', url: '..serverices/ajaxserver.asmx', data: 'lname='+ $('#lastname').val() }); return false; if #lastname has
$(document).ready(function() { $.ajax({ type: 'post', async: false, url: 'WebService.asmx/GetCustomerInformation', data: '{}', contentType: 'application/json;charset=ytf-8', dataType:
my javascript code $().ready(function () { $.ajax({ type: POST, url: ../WebService.asmx/GetDistricts, data: {}, contentType:
am calling a webservice from my jquery as $.ajax({ type: POST, url: /DataService.asmx/Search, contentType:
$(#button_title_delete).click(function(){ jQuery.ajax({type:'POST', url:'delete.php', data: 'id='+$(bid).val(), success: function(veri) { $(#delete_result).html(veri);} }); }); When i click
$.ajax({ type: POST, url: /zzz/bbb/abcd.aspx?deleteIDs= + request_ids, contentType: application/x-www-form-urlencoded, data: '', dataType: html, complete:
$.ajax({ type: POST, url:'/saveLayout', data: {id : layoutId, section : arrSection}, success: function(response){ $('#successMsg').addClass(errorBox);
The code I want to work: $.ajax({ type: POST, url: _Source/ajap/ajap.nlSrch.php, data: { sndJson
I have a form which POST's its data via AJAX: $.ajax({ type: POST, url:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.