Welcome Guest, Not a member yet? Register   Sign In
Dynamic ajax calls
#2

One approach to this would be to add data-* attributes to your form(s) which can hold data you need to handle your AJAX requests, then write some JavaScript which builds your AJAX request based on those attributes. If you use some sane defaults and check whether the attributes exist on each form, you should be able to use one function which examines the form(s) on the page and creates the appropriate submit handler(s), then binds the handler(s) to the submit event(s).

Similarly, you could get CI values into your JavaScript (without just writing them into the script) by adding a hidden input to the page with a pre-determined ID and JSON data in the value, or by attaching data attributes to an element on the page. Another possibility would be to add script to the page which defines an object containing your data before the main script is included, and have the main script look for that object. In any of these cases, you would still want the main script to use sane defaults and handle the absence of this data in a safe manner, so you don't have to include data on pages which don't need it.
Reply


Messages In This Thread
Dynamic ajax calls - by Urastor - 08-05-2015, 09:18 AM
RE: Dynamic ajax calls - by mwhitney - 08-05-2015, 10:48 AM
RE: Dynamic ajax calls - by Urastor - 08-06-2015, 02:58 AM
RE: Dynamic ajax calls - by mwhitney - 08-06-2015, 06:24 AM
RE: Dynamic ajax calls - by Urastor - 08-06-2015, 02:14 PM



Theme © iAndrew 2016 - Forum software by © MyBB