【问题标题】:Calling post in jQuery ajax giving error在jQuery ajax中调用post给出错误
【发布时间】:2014-09-20 07:29:20
【问题描述】:

我正在尝试使用 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 浏览器控制台没有返回任何响应。我已经在谷歌浏览器中尝试过,在网络选项卡下它显示了一些错误,我没有得到它。请帮帮我。

【问题讨论】:

    标签: jquery ajax


    【解决方案1】:

    您不能使用 javascript 执行跨源 ajax POST 请求。看看这个帖子 Cross domain ajax request

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-03
      • 2016-11-15
      • 1970-01-01
      相关资源
      最近更新 更多