简体   繁体   English

为什么Ajax脚本不能在本地工作?

[英]Why won't an Ajax Script Work Locally?

I've an issue with the same piece of code running fine on my live website but not on my local development server. 我有一个问题,同一段代码在我的实时网站上运行良好,但在我的本地开发服务器上却无法正常运行。

I've an Ajax function that updates a div. 我有一个更新div的Ajax函数。 The following code works on the live site: 以下代码可在实际站点上运行:

self.xmlHttpReq.open("POST", PageURL, true);
self.xmlHttpReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
self.xmlHttpReq.setRequestHeader("Content-length", QueryString.length);
//..update div stuff...
self.xmlHttpReq.send(QueryString);

When I try to run this on my local machine, nothing is passed to the QueryString. 当我尝试在本地计算机上运行此命令时,没有任何内容传递给QueryString。

However, to confuse matters, the following code does work locally: 但是,令人困惑的是,以下代码本地运行:

self.xmlHttpReq.open("POST", PageURL+"?"+QueryString, true);
self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
//..div update stuff..
self.xmlHttpReq.send(QueryString);

But, I can't use the code that works on my local machine as it doesn't work on the live server (they've changed their policy on querystrings for security reasons)! 但是,我无法使用在本地计算机上运行的代码,因为它在实时服务器上不起作用(出于安全原因,他们已更改了对查询字符串的策略)!

I can alert the Querystring out so I know it's passed into the function on my local machine. 我可以将Querystring发出警报,以便知道它已传递到本地计算机的函数中。 The only thing I can think of is that it's a hardware/update issue. 我唯一能想到的是这是硬件/更新问题。

Live Site is running IIS 6 (on a WIN 2003 box I think) Live Site正在运行IIS 6(我认为是在WIN 2003机器上)

Local Site is running IIS 5.1 (On XP Pro) 本地站点正在运行IIS 5.1(在XP Pro上)

Are there some updates or something I'm missing or something? 是否有一些更新或我缺少的东西?

Is there a reason you're explicitly setting the Content-Length header in the first example? 您是否有理由在第一个示例中明确设置Content-Length标头? You... shouldn't need to do this, and i wouldn't be surprised to find it causing problems. 你...... 应该不需要做到这一点,我也不会惊讶地发现它造成的问题。

Oh, and check your encoding routine. 哦,请检查您的编码例程。 The rules are not quite the same for querystrings and POSTed form data. 规则是不能很好地满足查询字符串相同,提交的表单数据。

我猜想Shog9是正确的,并且IIS 6我足够聪明,可以忽略您的请求并发送正确的标头,而5.2会引发错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM