I want to create a simple bookmarklet to pass some information from javascript to my Code Ignitor application.
This would need to use GET, but GET is disabled in CodeIgnitor and turning it on would require ment to re-write a few of the views and backend code which is out.
I want to pass 4 options (some are optional) into a method on my controller. Because some are optional it makes it a bit tricky to do
/controller/method/p1/p2/p3
but if p2 is optional, it throws it out a bit.
Ideally I was thinking I could do
/controller/method/p1
Where p1 is a json array.
However since this is a bookmarklet only basic and standard javascript functions can really be used.
If I could just do
/controller/method?p1=foo&p2=bar
would make life easier.
Any suggestions?
1.) You are not limited to "only basic and standard javascript functions" in a bookmarklet. You can use any library included already in the page, or you can use the bookmarklet to add the library first and then use it. To add a library to a page with a bookmarklet, simply append a script tag and use the onload attribute to execute the desired code after the library has loaded.
Here is a bookmarklet generator that will let you use jQuery with any bookmarklet: http://benalman.com/code/test/jquery-run-code-bookmarklet/ - you can follow links there for details. Because it's meant to create bookmarklets for nearly any type of page, the generator is creating code that is a bit more sophisticated than may actually be necessary in your case.
2.) Why not do something like this: /controller/method/p1=foo&p3=bar
and then very easily parse the string yourself. (Notice that this is not a get. There is no "?".)
Or similarly /controller/method/p1=foo/p3=bar
or /controller/method/p1-foo/p3-bar
.
3.) You can use default place holders that will be ignored by the server side code, like /controller/method/P1/null/P3
or /controller/method/P1/-/P3
.