从网站获取 ajax 输出?
大家好,我想在我的网站中使用以下网站页面的功能 http://www.unlockcodesource.com/buy_unlockcode_now.php
当用户选择手机品牌时(数字 3) 在页面中,ajax 调用发生在
http://www.unlockcodesource.com/ajax.js
并选择网络提供商(选择框)(数字 5)根据它进行更改。我尝试编写一些代码来实现该功能。首先我创建了 test.html 文件,其中有以下代码。
<html lang="en">
<head>
<title><!-- Insert your title here --></title>
<script language="javascript" src="ajax2.js"></script>
</head>
<body>
<!-- Insert your content here -->
<div id="buynow_container">
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" name="paypalform">
<select name="os1" onchange="GetNetworks(this.value,'select_make');">
<option selected value="0">Please select one</option>
<option value="Acer">Acer</option>
<option value="Alcatel">Alcatel</option>
<option value="Blackberry">Blackberry</option>
<option value="Dell">Dell</option>
<option value="G2X">G2X</option>
<option value="Garmin">Garmin</option>
<option value="Google">Google</option>
<option value="HP">HP</option>
<option value="HTC">HTC</option>
<option value="Huawei">Huawei</option>
<option value="INQ">INQ</option>
<option value="Iphone">Iphone</option>
<option value="LG">LG</option>
<option value="Motorola">Motorola</option>
<option value="Nokia">Nokia</option>
<option value="Optimus 2X">Optimus 2X</option>
<option value="Palm">Palm</option>
<option value="Pantech">Pantech</option>
<option value="Samsung">Samsung</option>
<option value="Sharp">Sharp</option>
<option value="Sidekick">Sidekick</option>
<option value="Siemens">Siemens</option>
<option value="Sony Ericsson">Sony Ericsson</option>
<option value="Zte">Zte</option>
</select>
<div id="select_make">
<select name="network" >
<option selected value="0">Please select make first!</option>
</select>
</div>
</form>
</div>
</body>
</html>
在 ajax2 .js 中,
function GetNetworks(value,divID) {
var xmlhttp;
xmlhttp = startAjax();
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) {
document.getElementById(divID).innerHTML = xmlhttp.responseText;
alert(xmlhttp.responseText);
}
}
xmlhttp.open("GET","http://www.unlockcodesource.com/getnetwork_list.php?ID="+divID+"&make="+value,true);
xmlhttp.send(null);
}
但 xmlhttp.responseText 返回 null。谢谢lz帮忙。如果您知道任何其他解决方案,例如解析或卷曲,请给出一些指导。谢谢
Hi people i want the functionality of the following website page in my site
http://www.unlockcodesource.com/buy_unlockcode_now.php
when user select the make of phone(number 3) in the page the ajax call happens in
http://www.unlockcodesource.com/ajax.js
and select network provider(select box) (number 5)changes according to it. I have try to write some code to achieve that functionality. First i created test.html file and there is following code in it.
<html lang="en">
<head>
<title><!-- Insert your title here --></title>
<script language="javascript" src="ajax2.js"></script>
</head>
<body>
<!-- Insert your content here -->
<div id="buynow_container">
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" name="paypalform">
<select name="os1" onchange="GetNetworks(this.value,'select_make');">
<option selected value="0">Please select one</option>
<option value="Acer">Acer</option>
<option value="Alcatel">Alcatel</option>
<option value="Blackberry">Blackberry</option>
<option value="Dell">Dell</option>
<option value="G2X">G2X</option>
<option value="Garmin">Garmin</option>
<option value="Google">Google</option>
<option value="HP">HP</option>
<option value="HTC">HTC</option>
<option value="Huawei">Huawei</option>
<option value="INQ">INQ</option>
<option value="Iphone">Iphone</option>
<option value="LG">LG</option>
<option value="Motorola">Motorola</option>
<option value="Nokia">Nokia</option>
<option value="Optimus 2X">Optimus 2X</option>
<option value="Palm">Palm</option>
<option value="Pantech">Pantech</option>
<option value="Samsung">Samsung</option>
<option value="Sharp">Sharp</option>
<option value="Sidekick">Sidekick</option>
<option value="Siemens">Siemens</option>
<option value="Sony Ericsson">Sony Ericsson</option>
<option value="Zte">Zte</option>
</select>
<div id="select_make">
<select name="network" >
<option selected value="0">Please select make first!</option>
</select>
</div>
</form>
</div>
</body>
</html>
and in ajax2 .js
function GetNetworks(value,divID) {
var xmlhttp;
xmlhttp = startAjax();
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) {
document.getElementById(divID).innerHTML = xmlhttp.responseText;
alert(xmlhttp.responseText);
}
}
xmlhttp.open("GET","http://www.unlockcodesource.com/getnetwork_list.php?ID="+divID+"&make="+value,true);
xmlhttp.send(null);
}
but xmlhttp.responseText is returning null. Thanks plz help. If you know any other solution like parsing or curl then please give some direction . Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这里讲一下限制跨域调用背后的小故事
Wikipedia
您拥有的解决方案之一是使用您的服务器(同一域)作为代理,我所说的代理是指一个网页,它可以获取其他域上的内容并将其发送回客户端。
现在从道德上讲我不确定这是否是一个好主意。
Here for the little story behind the restriction of cross domain call
Wikipedia
One of the solution you have is to use your server (the same domain) as a proxy, by proxy I mean a webpage that would fetch the content on the other domain and send it back to the client.
now ethically I am not sure if it's a good idea.
编辑
刚刚注意到您发布的 JS 表明您确实正在尝试使用您提到的网站中的数据,所以我的答案现在有点无关紧要。但我将把它留在这里,以防您稍后发现需要此信息。
正如 @mario 在评论中提到的,如果您尝试使用该网站的数据,则不能。
但是,如果您希望实现依赖/链接选择框,您可能需要查看这些 jQuery 插件:
这里有一些没有插件的教程:
EDIT
Just noticed that you've posted JS that shows you are indeed trying to use data from the website you've mentioned so my answer is kinda irrelevant now. But I'm going to leave it here in case you find that you need this information later.
As @mario mentions in the comment, if you're trying to use the data from that website, you can't.
However, if you're looking to implement the dependent/chained select boxes, you might want to check out these jQuery plugins:
Here are a couple of tutorials without plugins: