简体   繁体   中英

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. 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.

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. 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)

Local Site is running IIS 5.1 (On 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? 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会引发错误。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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