Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Posts
    905
    Thanks
    23
    Thanked 5 Times in 5 Posts

    XMLHTTP post Request - Page Headers?

    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?
    cheers,
    sir p

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    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.

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Posts
    905
    Thanks
    23
    Thanked 5 Times in 5 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •