如何申请使用AJAX网址网址、AJAX

2023-09-10 14:03:26 作者:关于傲娇的,高冷傲娇的

我在这个领域很新。 我需要找出如何使一个请求,使用Ajax我Solr的服务器 我怎么可以给一个网址(我的Solr服务器的URL)的请求 任何机构知道该如何面对呢? 我怎样才能使一个请求到下述网址

http://mysite:8080/solr/select/?q=%2A%3A%2A&version=2.2&start=0&rows=100&indent=on

下面请参阅:更正了code摘录如下

 函数getProductIds(){
    VAR XMLHTTP;
    如果(window.XMLHtt prequest)XMLHTTP =新XMLHtt prequest();
    否则XMLHTTP =新的ActiveXObject(Microsoft.XMLHTTP);
    xmlhttp.onreadystatechange =功能(){
        如果(xmlhttp.readyState == 4和&安培; xmlhttp.status == 200)console.dir(XMLHTTP);
        否则警报(没有反应);
        VAR ajaxURL =?的http://本地主机:8080 / Solr的/选择/ Q = *:*放大器;版本= 2.2&功放;启动= 0&​​放大器;行数= 100安培;缩进= ON;
        xmlhttp.open(GET,ajaxURL,真正的);
        xmlhttp.send();
    }
 

这是我的code,它总是呈现出无反应 谢谢你。

解决方案 ajax 无法获取session,为什么使用 Ajax 请求接口地址就不能获取 Session

您必须prepare发送请求之前的URL第一次使用javascript获取URL,然后连接$ C C是$像阿贾克斯格式以下

  VAR URL = location.href;
VAR ajaxURL = EN codeURIComponent(URL);
xmlhttp.open(GET,ajaxURL,真正的);
 

清楚地读你的问题后,似乎它是一个静态的URL,因此,你可以做以下

  VAR URL =HTTP://本地主机:8080 /等等等等等等;
xmlhttp.open(GET,URL,真正的);
 

您肯定就是GET请求。因为获得请求的大部分时间缓存中。还记录响应对象到Firebug的控制台和检查对象的了解更多。既然你没有反应,这意味着该服务器没有你任何你所提出的要求。

I am quite new in this area. I need to find out how to make a request to my solr server using Ajax How can I give a url(my solr server's url) in request Any body know how to deal with this? How can i make a request to the below mentioned url

http://mysite:8080/solr/select/?q=%2A%3A%2A&version=2.2&start=0&rows=100&indent=on

See here: Corrected the Code Snippet as below

function getProductIds() {
    var xmlhttp;
    if (window.XMLHttpRequest) xmlhttp = new XMLHttpRequest();
    else xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) console.dir(xmlhttp);
        else alert('no response');
        var ajaxURL = "http://localhost:8080/solr/select/?q=*:*&version=2.2&start=0&rows=100&indent=on";
        xmlhttp.open("GET", ajaxURL, true);
        xmlhttp.send();
    }

This is my code, it always showing "no response" Thanks.

解决方案

You will have to prepare the URL before sending in the request first get the URl using javascript and then encode it to ajax format like below

var URL = location.href;
var ajaxURL = encodeURIComponent(URL);
xmlhttp.open("GET",ajaxURL,true);

after reading your question clearly it seemed it is a static URL hence you can do below

var URL = "http://localhost:8080/blah blah blah";
xmlhttp.open("GET",URL,true);

Are you sure it is Get request. because get requests are most of the time cached. also log the response object into Firebug console and inspect the object to know more. Since you get no response that means the server did not send you anything for the request you made.