Encryption of Ajax calls

I use Ajax to pass a user-entered password to the server for checking using a PHP script.
The result is then returned as an answer of Yes or No.

My website uses SSL encryption. What I am wondering is… Does the Ajax call also use SSL? I have always assumed it did, but I thought I would ask away.

Thank you in advance for your reply.

Rodney

Hi Rodney,

Yes, unless you specify otherwise, the Ajax call will use the same protocol that your page is using (SSL). To force your call to be secure, you can use absolute URLs that specify the protocol. For example, to force the example from the wiki to be secure, it would be changed from this:

//Ajax example
req = Ajax("/sendData_ajax.php?myText=" + encodeURIComponent(txtSend.value));
if(req.status == 200) { //success
    txtResponse.value = req.responseText;
  } else { //failure
    txtResponse.value = "Error: "  +  req.err.message;
}

 //Sample POST call
req = Ajax("/sendData_ajaxPost.php" , "POST" , "myText="  +  encodeURIComponent(txtSend.value));

to this:

//Ajax example
req = Ajax("https://example.com/sendData_ajax.php?myText=" + encodeURIComponent(txtSend.value));
if(req.status == 200) { //success
    txtResponse.value = req.responseText;
  } else { //failure
    txtResponse.value = "Error: "  +  req.err.message;
}

 //Sample POST call
req = Ajax("https://example.com/sendData_ajaxPost.php" , "POST" , "myText="  +  encodeURIComponent(txtSend.value));

SBruck,

Thank you, I feel better now knowing Ajax call will be sent using SSL.

These examples you prepared for Get and Post Ajax calls are very interesting and informative. I had not considered using the complete URL for the Ajax call to be sure SSL is used. Also, I had not considered using a Post call. I have read in the past that one should use Post calls whenever possible but I had not thought of using Post in the Ajax call.

Thank you so much for the support and good information.

Rodney Wirtz

Hi Rodney,

I’m glad we were able to get your question resolved. Let us know if you have any further questions - we’re happy to help!