How should i process the data for sending form data via jQuery/Ajax?
I have a form which sends form data for p开发者_运维问答rocessing and accordingly receive the response. my forms have fields such as name, email, phone etc. the problem is while sending the data across if the name have spaces inbetween then it will send the data along with that spaces for example, the Ajax sends the following data as request for processing.
option=saveuser&gender=1&roleId=5&name=Mohmmed Noufil Damudi&email=i@i.com&password=mypassword&pPhone=8888888888&sPhone=8888888888
Is it ok to have spaces in between while sending request via Ajax? or am i doing the wrong way to send data? should i be converting the string to an array or jSON before sending? or does the above string look okay for sending the form data across the server for processing?
thank you.
Have a look at http://api.jquery.com/serialize/
Sending it this way, you can grab the data on your processing page from the $_POST-array.
If you are using ajax then it will be fine to send data with white spaces. no one will see change in url as page is not going to be refreshed.
when you are actually submitting form and choosing method as post then again, no one will so data in url so that will be fine too.
but when you are sending data via get method and form submission, I will recommend you to encrypt data or URL before sending it and decrypt it in corrosponding page for security aspects ...
It's okay to send data with spaces, those will be html encoded like other special chars.
精彩评论