Welcome Guest, Not a member yet? Register   Sign In
Using models with Scriptaculous's AJAX
#1

[eluser]tokyotech[/eluser]
I'm using the Flickr style in-place editor from Scriptaculous.
Code:
// javascript
new Ajax.InPlaceEditor('elementId', '/saveInfo.php');
So after someone clicks save, the form value is sent to saveInfo.php via $_POST, and that file is supposed to save the value into the database.

How would I be able to do this while being friendly with CodeIgniter's MVC? Shouldn't I be calling some function in one of my models? How do you simultaneously load the model and call one of its methods, while fitting inside this Scriptaculous function call?

My directory structure:
Code:
projectName
   + scripts
      * ajax
         - fileInPlaceEditorShouldCall.php
      * usingScriptaculous.js
   + system
      * application
         - controllers
            ~ thisPage.php
         - views
            ~ viewThatsIncludingUsingScriptaculousJS.php
#2

[eluser]n0xie[/eluser]
Just as you would with a normal form you just map it to a function inside your controller.

So in your case you could have a Controller called Ajax where you have different functions, in this case the function 'saveinfo'. In this function you would just get the post data the same way you would if it were posted by a standard form. If it validates, load up your model, safe the data, then instead of rendering a view, you probably want to send some status message either through xml or json depending on the outcome of the query.

Something like this:
Code:
// javascript
new Ajax.InPlaceEditor('elementId', '/ajax/saveinfo');
#3

[eluser]tokyotech[/eluser]
What is the correct URL if I don't have the index.php shortcut thing?

Code:
// javascript
new Ajax.InPlaceEditor('myTitle', '/index.php/ajax/saveInfo/title');

Code:
// in controllers/ajax.php
function saveInfo()
{
   echo 'testing: it has been saved';
}

After saving the form input field, this dumped my entire WAMP homepage into the field.
#4

[eluser]adaykin[/eluser]
What do you mean by index.php shortcut thing?

I am able to make ajax posts with prototype fine, here's an example of something that I am using in my code:

Code:
new Ajax.Request('http://localhost/AskMary/pageeditor/savepage', {
          method: 'post',
          parameters: { section: $(form['content']).getValue(), content: tinyMCE.get('pageValue').getContent() },
        onSuccess: function(transport) {
            var response = transport.responseText;
            $('updateMsg').update(response);
            $('updateMsg').show();
            new Effect.Highlight('updateMsg');
        },
        onException: showError
    });

So the controller name is pageeditor, and I am calling the savepage function inside of it.

http://localhost/AskMary is my base url.

I am using mod_rewrite, as described in the wiki
#5

[eluser]tokyotech[/eluser]
How can I do it without explicitly writing my base_url()? I want this to work both on localhost and on any webhost, regardless of the absolute position.

The mod_rewrite is too complicated for me to understand, so I just stick index.php in front of all my links.
#6

[eluser]davidbehler[/eluser]
Just add a js variable your index view file (or whatever you use to load your js files):
Code:
base_url = <?php echo base_url(); ?>;




Theme © iAndrew 2016 - Forum software by © MyBB