• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Concerns Regarding Ajax form submission and URL character limits

#1
[eluser]lanzd[/eluser]
I am in the process of writing a CMS and would like to use some AJAX to take care of some form submissions in the back end.

I have some concerns with the URL character limit because some of these forms contain a wysiwyg editor (CKFinder).

I have a few questions, some may be irrelevant after others are answered, but here we go.

Is it common practice to generate Ajax Requests to controllers with the URL structure
Code:
/controller/method/parameter1/parameter2/parameter3

The character limit on URL's imposed by each browser, does that only apply to when you type/paste/click an address into the address bar? or is it any request made with the browser?

When sending a get request via AJAX does the URL character limit apply?

Post doesn't seem to have a character limit (Not one that I have run into atleast with exception to size/timeout periods), So if sending a request in the form of
Code:
/controller/method/parameter1/parameter2/parameter3

I should generally be okay?

How would all this play with file uploads (This is a little broad, but I haven't written an AJAX file Uploader myself yet, only plugins)? If there is no form submission, the file doesn't actually get sent to the servers temp folder allowing me to start processing.

- Would I essentially have to have a separate form just for my file uploads which I would then trigger a submit/pass the temp folder name/process the file as normal in an AJAX called file? And finally return the resulting filename to the "Main" form with my text based data?
- How is it normally handled when/if the user closes the window before they hit submit on the "Main" form. (If it can/normally be/is handled this way)


#2
[eluser]lanzd[/eluser]
Regarding the file uploads, it is broad and not specific to CI, so I don't really expect any type of answer for that. I just figured I'd ask to get a consensus of how people usually decide to do it.

I may have answered a lot of my own questions. The method parameters in my controllers are my GET variables.

Quick question: Can I also access these with the code:

Code:
$this->input->get('some_data', TRUE);

or is it neither POST or GET and just parameters of a method. I believe it is the latter but I supposed I can think of it as GET but know it really isn't technically.

As far as AJAX and CI am I able to just use the structure

Code:
/controller/method

and set the AJAX for a POST request. Then pass my form field values no differently then I would normally.
Then I should be able to just access each value with:

Code:
$this->input->post('some_data');

where 'some_data' is whatever name I used for my
Code:
name:value
pairs in my AJAX request.

Still new to CI and I don't know why I felt I could only pass the values as if they were to be picked up by method params.

I don't see why this shouldn't work, and once I get home I'll try it to confirm.

I'll post back just as either a confirmation or to say it doesn't work.

Many thanks.

#3
[eluser]Pert[/eluser]
If you submit data on URL, it might cause problems with URL being limited to very specific set of characters.

With AJAX you can submit post data and pick it up on controller side with $this->input->post('var_name').

URL structure should only use IDs or short keywords and not be used to really pass updates to controllers.

For file uploads, you can read more here http://ellislab.com/codeigniter/user-gui...ading.html

File data is not in $_GET or $_POST but in $_FILES global variable.

#4
[eluser]lanzd[/eluser]
All right, thank you very much.

Again, I don't know why I felt I had to pass my data in a

Code:
/controller/method/var1/var2/var3

format.

I guess it was either a brain fart, or I temporarily thought CI was just magic and didn't still follow http/php rules. Silly me lol.

#5
[eluser]Pert[/eluser]
Haha, all good mate.

Using URL does come in handy for various things, for example, you could say what type of content you want to create

Form for content ID 1
Code:
/content/details/1

Show empty form for blog content type
Code:
/content/details/type/blog


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.