2014-09-20 7 views
0

Я пытаюсь вызвать службу обслуживания из JQuery ajax с помощью метода POST. Ниже приведен код:Вызов сообщения в jQuery ajax, дающий ошибку

<!DOCTYPE html> 
<html> 
<head> 
<script src="lib/js/jquery/jquery-1.7.2.min.js"></script> 
</head> 
<body> 
    <div id="div1"> 
     <h2>Let jQuery AJAX Change This Text</h2> 
    </div> 
    <button id="totalRevenue">Get External Content</button> 

    <script> 
function jsonpCallback(response) { 
    console.log("response from server: "+JSON.stringify(response)); 
    }; 

$(document).ready(function() { 
    $("#totalRevenue").click(function() { 
      console.log('inside function'); 
      var input = { 

         "facets": { 

         "stats": { 

          "statistical": { 

          "field": "@fields.TransTotalAmount" 

          }, 

          "facet_filter": { 

          "fquery": { 

           "query": { 

           "filtered": { 

            "query": { 

            "bool": { 

             "should": [ 

             { 

              "query_string": { 

              "query": "*" 

              } 

             } 

             ] 

            } 

            }, 

            "filter": { 

            "bool": { 

             "must": [ 

             { 

              "range": { 

              "@timestamp": { 

               "from": 1411136110765 , 

               "to": "now" 

              } 

              } 

             } 

             ] 

            } 

            } 

           } 

           } 

          } 

          } 

         }, 

         "stats_All Transactions": { 

          "statistical": { 

          "field": "@fields.TransTotalAmount" 

          }, 

          "facet_filter": { 

          "fquery": { 

           "query": { 

           "filtered": { 

            "query": { 

            "bool": { 

             "should": [ 

             { 

              "query_string": { 

              "query": "*" 

              } 

             } 

             ] 

            } 

            }, 

            "filter": { 

            "bool": { 

             "must": [ 

             { 

              "range": { 

              "@timestamp": { 

               "from": 1411136110765 , 

               "to": "now" 

              } 

              } 

             } 

             ] 

            } 

            } 

           } 

           } 

          } 

          } 

         } 

         }, 

         "size": 0 

        }; 

     $.ajax({ 
       type:"POST", 
       url:"http://esu2v977:9200/labs-uat-2014-09-19/_search", 
       dataType:"jsonp", 
       contentType:"application/javascript; charset=UTF-8", 
       data:JSON.stringify(input), 
       successs:jsonpCallback, 
        error: function(data) { 
        console.log("there is some problem to get the response :" 
           +JSON.stringify(data)); 
       } 
      }); 
    }); 

}); 
</script> 
</body> 
</html> 

Он не возвращает никакого ответа в консоли браузера Firefox. Я пробовал в google chrome, по вкладке сети он показывает некоторую ошибку, я не получаю ее. Пожалуйста, помогите мне.

ответ

0

Вы не можете выполнить запрос ajax запроса перекрестного происхождения, используя javascript. Посмотрите на этот пост Cross domain ajax request

Смежные вопросы