Group: 忙吧外挂天地

D I S C U S S I O N
电子商务方面的问题:用Ajax来访问mangbar资源

sevenredcity
05/28/2008 16:39 ... 113hits
<html>
<head>
<title>使用JSON插件</title>
</head>
<script src="prototype-1.4.0.js" type="text/javascript">
</script>
<script language="JavaScript">
function gotClick()
{
alert("11111111111111");
//请求的地址
var url = 'www.mangbar.com/extension/login';
//将form1表单域的值转换为请求参数
var params = Form.serialize('form1');
//创建Ajax.Request对象,对应于发送请求
var myAjax = new Ajax.Request(
url ,
{
//请求方式:POST
method:'post',
//请求参数
parameters:params,
//指定回调函数
onComplete: processResponse,
//是否异步发送请求
asynchronous:true
});
}
function processResponse(request)
{
alert("222222222") ;
$("show").innerHTML = request.responseText;
}
</script>
<body>
<form id="form1" name="form1" method="post">
<INPUT TYPE="text" name="email" id="email"/><br>
<INPUT TYPE="password" name="password" id="password"/><br>
<INPUT TYPE="button" value="提交" onClick="gotClick();"/>
</form>
<div id="show">
</div>
</body>
</html>


里面的url是否无效,老是提交不了!
我使用了prototype(显示Ajax),如果单纯写html页面可以访问到,但是我要读取json对象在页面上显示!

请指教,谢谢!
Current topic has 7 replies | Back |
#1 西瓜 05/28/2008 16:46
提交不了具体是什么意思?

这个url是正常的, 忙吧的firefox插件以及其他所有的外挂服务都是调用这个服务的. json本身的mime type是 "text/json", 需要自己解析成javascript对象. 也许是你的json解析有问题?
#2 sevenredcity 05/28/2008 16:49
我如果使用在J2EE框架,把url改成*.action,是没问题的!有可能是url的转义问题!
#3 sevenredcity 05/28/2008 16:51
西瓜兄说得也有道理!我再改改!
#4 西瓜 05/28/2008 16:55
有点晕..你是用javascript还是Java在调用这个API? 如果是java在你的服务器端调API, 是用HttpURLConnection吗?

在这里url转义是什么意思?
#5 sevenredcity 05/28/2008 16:58
问题确定不是URL转义问题了! 
是JavaScript调用该API!
我所说的是我那个应用在J2EE是可以运行的。
这个只是把表现层页面拿来访问mangbar的API。
#6 sevenredcity 05/28/2008 17:13
我猜URL的字符串在传输过程中会需要转义,比如/转义是//,现在确定不是这个问题了!
#7 sevenredcity 05/29/2008 16:40
A basic example
var url = '/proxy?url=' + encodeURIComponent('www.google.com/search?q=Prototype'); // notice the use of a proxy to circumvent the Same Origin Policy. new Ajax.Request(url, {   method: 'get',   onSuccess: function(transport) {     var notice = $('notice');     if (transport.responseText.match(/href="http:\/\/prototypejs.org/))       notice.update('Yeah! You are in the Top 10!').setStyle({ background: '#dfd' });     else       notice.update('Damn! You are beyond #10...').setStyle({ background: '#fdd' });   } }); 

还是url的问题,查了Prototype1.6官方帮助文档。

var url = encodeURIComponent('www.google.com/search?q=Prototype');
Return To Top | Back