bomaboom
bomaboom

Reputation: 300

indexing solr using jquery AJAX

Is is possible to index (add/update) solr using jquery AJAX?

There is no example in net and I have been trying but no success. Below is my code

 try {
            $.ajax({
                type: "POST",
                url: "http://192.168.10.113:8080/solr/update/json?commit=true",
                data: { "add": { "doc": { "id": "222222", "name": "Ruby on Trails"}} },
                contentType: "application/json",
                dataType: 'jsonp',
                crossDomain: true,
                jsonp: 'json.wrf',
                success: function (data) { alert(data); },
                failure: function (errMsg) {
                    alert(errMsg);
                }
            });
        }
        catch (err) {
            alert(err);
        }

My tomcat server log is mentioned below. [31/Oct/2012:15:56:24 +0530] "GET /solr/update/json?commit=true&json.wrf=jQuery1820996771614998579_1351662048057&add%5Bdoc%5D%5Bid%5D=222222&add%5Bdoc%5D%5Bname%5D=Ruby+on+Trails&_=1351678643653 HTTP/1.1" 200 159

Though it says 200, the document is not added in solr. I have waited enough and repeated the process several times to remove the commit strategy of solr server being the culprit here. In chrome browser it says Uncaught SyntaxError: Unexpected token < But that's too generic to take any guess. It is some other issue. Any help is appreciated.

Upvotes: 3

Views: 1495

Answers (2)

Mark Robson
Mark Robson

Reputation: 1328

I had the same problem. This site helped me out:

$.ajax({
    url: "...",
    dataType: 'jsonp',
    jsonp: 'json.wrf',
    data: {
      q: "tag:" + request.term + "*"
    },
...

Upvotes: 1

rudy22
rudy22

Reputation: 11

You need to double check what you're actually doing. First, the uncaught exception in the browser is a bad sign since it will stop any javascript execution once raised. Even if you were doing the solr update succesfully you wouldn't see the success and error functions. Make sure you get rid of it before going any further. Secondly, you are doing a POST request and your log is showing a GET. Are you sure that log entry corresponds to the jQuery request?

Upvotes: 1

Related Questions