0

Brand new to using JSon/ajax. Trying to replicate this jQuery UI Autocomplete using a static json file as source just as an example. I'm not positive I'm referencing this correctly if someone could let know whats wrong. Getting a (Uncaught ReferenceError: request is not defined)

<form id="searchform" method="get" role="search">
                <input id="searchfield" />
                <input type="submit" name="go" value="go!" />
            </form>


<script src='js/jquery-1.11.0.min.js'></script>
<script src="js/autocomplete/jquery-ui-1.10.3.custom.js" type="text/javascript" charset="utf-8"></script>

<script>
    $(function() {
    $.ajax({
        url: "json/Providers.json",
        dataType: "json",
        data: {term: request.term},
        success: function(data) {
            var cat_data = $.map(data, function(item) {
                return {
                    ProviderID: item.ProviderID,
                    Name: item.Name,                  
                };
            });
            $("#searchfield").catcomplete({
                delay: 0,
                source: cat_data,
                minlength:0
            });
        }
    });
});
</script>

json format

   {"Providers":[{"ProviderID":"3","NAME":"name1"}, 
    {"ProviderID":"4","NAME":"name2"},  
    {"ProviderID":"5","NAME":"name3"}]} 
4
  • 1
    request is not defined. So what are you expecting request to be?! From where you copied this code you should be able to find where request is defined... Commented Jan 13, 2014 at 15:08
  • 2
    The message is pretty clear: request.term (request is not defined) Commented Jan 13, 2014 at 15:08
  • is 'request' a function in the jquery file? What do I need to replace it with? Commented Jan 13, 2014 at 15:09
  • @user1 Request is an object, test by replacing it by a string firstly: {term: "anything i want to search for"} But if you have no idea what you are looking for, please start by reading some basic tutos Commented Jan 13, 2014 at 15:13

2 Answers 2

0

This particular data: {term: request.term}, is the problem

You need to define any javascript variable before accessing them.

 var request;

In your case data is not required. Just remove data: {term: request.term} since you are loading the static .json file

Sign up to request clarification or add additional context in comments.

3 Comments

What would I replace request with? I assumed that was a function from the jQuery file.
data is to send parameters to the server. I guess you can remove it
removing it gives me more erros, please see my comments on the other answer
0

Since you're a reading json file, it is clear there is no need to pass any parameter. So remove data: {term: request.term}

9 Comments

get more errors removing it: OPTIONS file:///C:/Users/jswanson/Desktop/Survey/json/Providers.json No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
also this one: XMLHttpRequest cannot load file:///C:/Users/jswanson/Desktop/Survey/json/Providers.json. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
Ajax is the act of making HTTP requests from JavaScript. Stop trying to do it without HTTP. Run a web server.
@user1 this is called CORS.. you can overcome by changing dataType from json to` jsonp` or nove on to web servers.
only change the dataType and nothing else? still getting similar errors.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.