Can I send Data to Controller after AJAX Success in PHP Codeigniter?

Can I send Data to Controller after AJAX Success in PHP Codeigniter?



I want to send "data" to the controller that came from controller to success of ajax and its a different controller function then the first one.


$.ajax(
url :'<?= base_url('Content/get_thumb') ?>', // Controller URL
type : 'POST',
data : formData,
async : false,
cache : false,
contentType : false,
processData : false,
success : function(data)
$('#video_thumb').show();
$('#thumb_image').html('<img src="' + data + '" style="margin-top:57px;" /> ');

);






Yes you can, have you considered adding another ajax call in your success function

– Dale
Sep 6 '18 at 10:43







What have you tried? Since this is very well possible by just writing a second ajax call in the success part.

– Loek
Sep 6 '18 at 10:44


success






Actually i'm new to ajax so let me try that.i didn't know about that.btw thanx

– Scarface
Sep 6 '18 at 10:48




1 Answer
1



Yes you can, just after success function you can run another function that will send data back to your controller.


$.ajax(
url :'Controller URL', // Controller URL
type : 'POST',
data : formData,
async : false,
cache : false,
contentType : false,
processData : false,
success : function(data)
$('#video_thumb').show();
$('#thumb_image').html('<img src="' + data + '" style="margin-top:57px;" /> ');
function_name(data); //run another function to send data.

);



The function to run on sucess


<script type="text/javascript">
function function_name(DataToSend) {
$.ajax(
url :'<?= base_url('Content/get_thumb') ?>', // Controller URL
type : 'POST',
data : DataToSend,
success : function(response)
//Do what needs to be done

);
</script>






how can i get success "data" of 1st ajax into the second ajax?

– Scarface
Sep 6 '18 at 11:09






@Scarface pass the data as argument in the second function as I did in the post

– Masivuye Cokile
Sep 6 '18 at 11:10






yaa it solved the problem thanx

– Scarface
Sep 6 '18 at 11:14



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)