I have an autosuggest done in PHP which on selection will provide to me the id of the item selected from the auto suggest. I would like to post the id that was selected to the server. What would be the best practice to store this variable and sent the same to the server via HTTP Post in PHP?
Steps:
- List data from a Auto Suggest Text Box. (This is done using javascript).
- Select an Item from the Auto Suggest and also store the key value for the se开发者_运维百科lection in a data store that can be sent over HTTP Post. (The data store is what I am not able to understand)
- Post the form to the server.
I tried to store the value into a hidden field and my javascript breaks, not sure why. Is there any other data store mechanism that I can use other than hidden fields?
Could someone please guide me through this as I am pretty new to PHP.
Thanks and Regards Abishek R Srikaanth
Your javascript may be breaking due to unescaped ' or some other parsing error. Check your browser's javascript console (firefox and chrome have it) for the error.
Hidden field is the way to go. So instead of using other method, try to fix the JS code.
- First of it would help use tremendously if you showed us some code(like other users asked for) to work with. This enables me/us to give you a better answer. You don't have to show all the code but just enough to give us a demonstration(if code should remain private). You can use http://jsfiddle.net/ to host the code easily for us.
- Are you using any framework? I would advise you to use JQuery because it is a really nice framework and I believe you could achieve your task with JQuery easily.
- I think you should be using HTTP GET instead of POST because POST should not be cached(idempotent) according to HTTP-Specs and I believe your data can and should be cached?
精彩评论