Package Ajax
Permalink
Hello everybody,
I made a package which add dashboard single page,
In this single page, i want to make a simple ajax request but ajax not found url on my ajax php file.
For my example :
Ajax request success but i think sauvegarde.php is not found.
Can you help me please ?
Thank you in advance ;-)
I made a package which add dashboard single page,
In this single page, i want to make a simple ajax request but ajax not found url on my ajax php file.
For my example :
$.ajax({ url : "<?php echo $this->url($resultTargetURL) ?>/index.php/packages/configurateur_devis/sauvegarde.php", type : 'POST', data: 'idQuestion='+idQuestion+'&nom='+$(lien).parent().find('input.question').val()+'&prix='+$(lien).parent().find('input.prix').val() }).success(function(msg) { alert(msg); });
Ajax request success but i think sauvegarde.php is not found.
Can you help me please ?
Thank you in advance ;-)
Have a look at my AJAX lessons howto and associated addon. It includes working examples of the code @hutman suggests.
Hello, thank you for your answers,
But it not works in 5.7 :(
But it not works in 5.7 :(
This is an article about Ajax in 5.7. Tools are deprecated and you can now use methods / views in your controller.
http://c5hub.com/learning/ajax-57-style/...
http://c5hub.com/learning/ajax-57-style/...
Hello rge and thank you,
I have already found this link but i not understand everything.
In my package, how to modify application/bootsrap/app.php ?
If i have a controller for a single page in my package, can i create ajax method and call this in javascript simply ?
I have already found this link but i not understand everything.
In my package, how to modify application/bootsrap/app.php ?
If i have a controller for a single page in my package, can i create ajax method and call this in javascript simply ?
You don't need to.
In the view file. You make the Ajax call like this
products.php (single page)
Controller ajax_call function
Also read this part of the documentation
http://www.concrete5.org/documentation/developers/5.7/working-with-...
In the view file. You make the Ajax call like this
$(document).ready(function(){ $.ajax({ url : "<?php echo URL::to('/products', 'ajax_call'); ?>" , success : function(rs){ $('#ajax-content').html(rs); } }); }); // "/products" is the path of the single page // "ajax_call" is the function that will be called in the controller of the single page.
products.php (single page)
Controller ajax_call function
Also read this part of the documentation
http://www.concrete5.org/documentation/developers/5.7/working-with-...
Thank you ! It works perfectly :)
One last question, what is the use of 'exit' ?
One last question, what is the use of 'exit' ?
If you don't exit the full html will be returned. In this example it will be only the string.
Ok thank you, have a nice day !
Hello all, i have another question about ajax, for single pages, ajax in controller works,
but in my block, how i call ajax method in block controller ?
I try to put my ajax method in controller already installed with package but redirect to login page.
Anybody have a solution ?
Thank you :)
but in my block, how i call ajax method in block controller ?
I try to put my ajax method in controller already installed with package but redirect to login page.
Anybody have a solution ?
Thank you :)
You should read this article to get the needed information:http://www.concrete5.org/documentation/developers/5.7/working-with-...
Step 1
In the view.php you need to make an Ajax call. Use to create the url.
The code should look like this.
In the documentation is mentioned that $view->action(); provides automatically the bID. This seems to be not the case. That is why I append it my self.
Step2
Create the action in the controller. This should have the same name as provided in the action in the view prefixed with "action_".
Step 1
In the view.php you need to make an Ajax call. Use
$view->action('');
The code should look like this.
$(document).ready(function(){ $.ajax({ url : '<?php echo $view->action("ajax_call") . "/" . $bID ?>', success : function(rs){ $('#ajax-content').html(rs); } }); });
In the documentation is mentioned that $view->action(); provides automatically the bID. This seems to be not the case. That is why I append it my self.
Step2
Create the action in the controller. This should have the same name as provided in the action in the view prefixed with "action_".
Work like a charm, Thank you rge !
Replace your line
With