php - Pass ID of Entity via Ajax to Controller -
what best way pass identifier of object via ajax server / controller (e.g. on site "book/edit/mybookname" , update book entity "mybookname" via ajax) ?
i thought of approaches , wanted know, common , secure way be:
1) pass id of book controller
-> problem: id variable / field can changed using console of browser
2) pass current url (window.location.href) controller , extract name out of url in controller
-> window.location.href can't changed through console ..?
i know have check on server side, if user should have access edit entity. if has more 1 book, possibly change id parameter book owns , change book presentation in background, not 1 browsing.
thought ajax can use post data. can not edited in browser address bar.
var xmlhttp; } if (window.xmlhttprequest) {// code ie7+, firefox, chrome, opera, safari xmlhttp=new xmlhttprequest(); } else {// code ie6, ie5 xmlhttp=new activexobject("microsoft.xmlhttp"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readystate===4 && xmlhttp.status===200) { //do whatever response } }; xmlhttp.open("post","ajax/ajax.php); xmlhttp.setrequestheader("content-type","application/x-www-form-urlencoded"); xmlhttp.send("field1=whatever&field2=whateverelse");
Comments
Post a Comment