View Full Version : XMLHTTP post Request - Page Headers?

sir pannels
12-07-2006, 05:51 PM
hi all,

When using xmlhttp request for POST as you may know you can have a form target to somefile.php .asp, whatever) and put return false in the onsubmit tag also so the form does not actually submit, yet somefile.php still runs.

That somefile.php just returns a value, the ajax then puts that value in a div..

Problem I have is I do not understand why you need to set content type of somefile.php. Strictly speaking, is it even being called in the browser for display?

The reason I ask is because I set the content type of the file to text/plain and internet explorer just asks me if I want to download or save somefile.php when I submit the form. In opera, it seems to fully submit the form and instead of returning value to the <div> it actually sends me to an entire new page with the value on.

Not really a php question more and ajax/js one so hope i get away with it here.

anyone have any thoughts?
sir p :D

12-07-2006, 06:09 PM
When you make a post you should set:
req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

You really just need to set the content type when we are using XML, using responseText really does not care about the type.


sir pannels
12-08-2006, 03:07 PM
hi eric,

thanks for that.

I have set the type for the request but on the server side script you also need to set the content type

Im gonna post in the PHP forum thin its more of that

cheers for you time :)