Jump to content



Photo

Ajax Post Method

Is POST data encrypted?

  • Please log in to reply
5 replies to this topic

#1 Hope4You

Hope4You

    Newbie

  • Members
  • Pip
  • 14 posts

Posted 29 August 2011 - 3:17 PM

Using Ajax, I want to use the POST method with https://
example:
ajax.open("post","https://example.com/submit.php", true));
ajax.send("name=John");

What I want to know is: will the POST data (in this case, John) be encrypted as it is sent to submit.php?

----------------------------------------------

I would also like to know: should ajax.setRequestHeader("Content-type","application/x-www-form-urlencoded"); be placed between ajax.open() and ajax.send() if I use the POST method? Another site says to use it.
  • 0

#2 HartleySan

HartleySan

    Advanced Member

  • Members
  • PipPipPip
  • 2,923 posts
  • LocationColumbus, OH USA

Posted 29 August 2011 - 7:58 PM

I always place ajax.setRequestHeader("Content-type","application/x-www-form-urlencoded"); between the open and send methods. I think the post won't work otherwise, but don't quote me on that.

Also, I am assuming that the data is properly encrypted, just like a standard post request, but again, don't quote me on that.

Sorry I couldn't be of more help. I trust someone will provide a real answer soon enough.
  • 0

#3 Hope4You

Hope4You

    Newbie

  • Members
  • Pip
  • 14 posts

Posted 26 October 2011 - 5:00 PM

Okay, thank you. So now I have another question: In the "PHP 5 Advanced 2nd edition" book on page 526, Larry says that "using POST in your Ajax won't work properly with the PHP script".

1. What's the actual problem with using POST to send data from Ajax to PHP script? So far my testing has worked - PHP received the POST data.
2. Should I only use GET with Ajax?

Thank you! These forums have given me a lot of help.
  • 0

#4 Larry

Larry

    Administrator/Writer

  • Administrators
  • 3,906 posts
  • LocationState College, PA (USA)

Posted 26 October 2011 - 7:25 PM

I don't have the book in front of me, but I suspect I write that using POST in the Ajax won't work with the PHP script because the PHP script expects data to be transmitted via GET. If you use POST in Ajax, you just need to change the PHP script accordingly.

There's no reason you can't use POST with Ajax, but the decision on GET vs. POST should be the same as any time you're deciding between the two (i.e., POST is meant to affect changes or actions on the server; GET is intended to retrieve information).

Thanks for the nice words on the forums!
  • 0

#5 Hope4You

Hope4You

    Newbie

  • Members
  • Pip
  • 14 posts

Posted 27 October 2011 - 4:25 PM

Thank you. After thinking a little more on the topic, I believe that the reason why I have no problems using POST with Ajax is because I add this line of code:

ajax.setRequestHeader("Content-type","application/x-www-form-urlencoded");//to those who want to use this line of code: remember to replace the variable "ajax" with your variable name

Which will then send the POST data just like a normal HTML form!
  • 0

#6 Larry

Larry

    Administrator/Writer

  • Administrators
  • 3,906 posts
  • LocationState College, PA (USA)

Posted 28 October 2011 - 7:50 AM

No, that line just sets the content-type. POST vs GET is set using different code.
  • 0