1

I've got this problem that I can't solve. Partly because I can't explain it with the right terms. I'm new to this so sorry for this clumsy question.

Below you can see an overview of my goal.

I'm using Magento CE 1.7.0.2 & Solr 4.6.0.

var url1 ="http://127.0.0.1:8080/solr/select?q=iphon&wt=json&json.wrf=?";
$.getJSON(url1,function(result){
   // my logic 
});

when the Solr Server is Running means this script is working fine.But if my Solr Server is Not Running means it'll not work.

But my goal is to write this script like this...

if( Solr Server is Running){
   var url1 ="http://127.0.0.1:8080/solr/select?q=iphon&wt=json&json.wrf=?";
   $.getJSON(url1,function(result){
      // my logic-1
   });
}else{
   // my logic-2
}

So how do i know that whether the Solr Server is running or Not ?

& i know this is the duplicate question but i never find solution so please ignore it.

Any Ideas ?

Naresh
  • 681
  • 2
  • 12
  • 39

4 Answers4

0

Don't know how SOLR works, but proper jQuery would be:

$.ajax({
    type: "GET",
    url: "http://127.0.0.1:8080/solr/select?q=iphon&wt=json&json.wrf=?",
    dataType: "json",
    success: function (result) {
        // is working
    },
    error: function (result) {
        // probably not
    }
});
Michał
  • 2,456
  • 4
  • 26
  • 33
  • i tried this one its working fine when the Solr Server is running But when i turned off the Solr Server its not getting inside error: – Naresh Mar 10 '14 at 07:59
  • What's the server response when it's working? When server isn't working, does ajax call cause any error (in firebug console for example)? Do you need to receive JSON data or just check if server responds? – Michał Mar 10 '14 at 10:41
  • When server is running means its its going in inside Success function But Server is not running means its not going in side to Error function. – Naresh Mar 11 '14 at 10:37
  • If so, then we don't even need to use `json`. Try my code without `dataType: "json",`. – Michał Mar 11 '14 at 10:40
0

Use setTimeout before trying to connect. If you are successful use clearTimeout. If you are not within the setTimeout-time you can do what you have defined setTimeout to do.

heinob
  • 19,127
  • 5
  • 41
  • 61
0

You could just use the built in Solr Ping handler:

http://hostname:port/solr/admin/ping

This will give you the info you need.

Si

Simon
  • 1,613
  • 1
  • 12
  • 27
0
<?php 
       $solr = new Apache_Solr_Service( 'HOST', 'PORT NUM', '/solr' );
       if ( $solr->ping() ) {
          // APACHE SOLR SERVER IS RUNNING 
       }else{
          // APACHE SOLR SERVER IS NOT RUNNING
       }
?>

I hope it will use full for some one.

Naresh
  • 681
  • 2
  • 12
  • 39