如何申请使用AJAX网址 [英] How can I request a url using AJAX

查看:139
本文介绍了如何申请使用AJAX网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

<$p$p><$c$c>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,它总是呈现出无反应
谢谢你。

解决方案

您必须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.

这篇关于如何申请使用AJAX网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆