JavaScript Retrieve results from SOLR using jquery calls retrieve results from multiple google pages,retrieve results from mysql,

I am working to get response from SOLR using jquery. When I use the below code I got the error saying Typeerror:data is null

When looked at the code in firebug, data in on_data function is null. I think I am missing something in the Solr URL.The URL I am using is http://xxxx.xxx.xxxx.xxx/xxx_xxx/core0/selectcore0/select/?q=%3A&version=2.2&start=0&rows=10&indent=on&wt=json. Can you please take a look at my code, and also suggest me the URL style in the code

<html>
<head>
    <title>Solr Search</title>
</head>
<body>
    <h3>Solr Search</h3>

    Query: <input id="query" /> 
    <button id="search">Search</button>
    <hr/>
    <div id="results">
    </div>
</body>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script>
    function on_data(data) {
        $('#results').empty();

        var docs = data.response.docs;
        $.each(docs, function(i, item) {
            $('#results').prepend($('<div>' + item.name + '</div>'));
        });

        var total = 'Found ' + docs.length + ' results';
        $('#results').prepend('<div>' + total + '</div>');
    }

    function on_search() {
        var query = $('#query').val();
        if (query.length == 0) {
            return;
        }

        var url='http://xxxx.xxx.xxxx.xxx/xxx_xxx/core0/selectcore0/select/?q='+query+'&version=2.2&start=0&rows=50&indent=on&wt=json';
        $.getJSON(url, on_data);
    }

    function on_ready() {
        $('#search').click(on_search);
        /* Hook enter to search */
        $('body').keypress(function(e) {
            if (e.keyCode == '13') {
                on_search();
            }
        });
    }

    $(document).ready(on_ready);
</script>

Answer:1

Here is the working version of your code, and list of changes: 1) added wrf: adds a wrapper-function around the JSON response, useful in AJAX with dynamic script tags for specifying a JavaScript callback function 2) added callback: need to use JSONP instead of an ordinary JSON request, due to JavaScript’s cross-domain security restrictions.

<html>
<head>
    <title>Solr Search</title>
</head>
<body>
    <h3>Solr Search</h3>

    Query: <input id="query" /> 
    <button id="search">Search</button>
    <hr/>
    <div id="results">
    </div>
</body>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script>
    function on_data(data) {
        $('#results').empty();
        var docs = data.response.docs;
        $.each(docs, function(i, item) {
            $('#results').prepend($('<div>' + item.name + '</div>'));
        });

        var total = 'Found ' + docs.length + ' results';
        $('#results').prepend('<div>' + total + '</div>');
    }

    function on_search() {
        var query = $('#query').val();
        if (query.length == 0) {
            return;
        }

        var url='http://xxxx.xxx.xxxx.xxx/xxx_xxx/core0/selectcore0/select/?q='+query+'&version=2.2&start=0&rows=50&indent=on&wt=json&callback=?&json.wrf=on_data';
        $.getJSON(url);
    }

    function on_ready() {
        $('#search').click(on_search);
        /* Hook enter to search */
        $('body').keypress(function(e) {
            if (e.keyCode == '13') {
                on_search();
            }
        });
    }

    $(document).ready(on_ready);
</script>
Answer:2

Since you are using $.getJSON, you might need to add &wt=json to your query.

So your query should be: http://xxxx.xxx.xxxx.xxx/xxx_xxx/core0/selectcore0/select/?q=search_query&version=2.2&start=0&rows=10&indent=on&wt=json

By default Solr gives XML response. You need to specify if you need JSON response by adding &wt=json

Mode detail: http://wiki.apache.org/solr/SolJSON

Answer:3

Basically I want to be able to select the div level2 parent from the child level4 div. My application does not has such classes, otherwise I'd just select level2 :) <div class="level1"> <...

Basically I want to be able to select the div level2 parent from the child level4 div. My application does not has such classes, otherwise I'd just select level2 :) <div class="level1"> <...

  1. jquery select child element
  2. jquery select child by class
  3. jquery select child of this
  4. jquery select child of id
  5. jquery select child of parent
  6. jquery select child input
  7. jquery select child by index
  8. jquery select child of div
  9. jquery select child of element with class
  10. jquery selector child of sibling
  11. jquery select child span
  12. jquery select child class of parent
  13. jquery select child element by tag
  14. jquery select child element with specific class
  15. jquery select child by tag
  16. jquery select child by name
  17. jquery select child element of parent
  18. jquery select child element by name
  19. jquery select child button
  20. jquery select child by type

The help that I received from other users on this forum didn't help at all ... I have a chart that is generated through google charts API on this link http://imageshack.us/f/9/capturesfn.png/ ...

The help that I received from other users on this forum didn't help at all ... I have a chart that is generated through google charts API on this link http://imageshack.us/f/9/capturesfn.png/ ...

I am using sails.js to create a tag system that has many-to-many relations with an entity called Post. The way I am doing the association is to use a database table to correlate each tagId with the ...

I am using sails.js to create a tag system that has many-to-many relations with an entity called Post. The way I am doing the association is to use a database table to correlate each tagId with the ...

  1. using lib async

Question Is it possible to know if the function was fired by a user event or an async event (like callback) without having the original event parameter? Background I'm trying to determine the event ...

Question Is it possible to know if the function was fired by a user event or an async event (like callback) without having the original event parameter? Background I'm trying to determine the event ...

  1. javascript know event listeners