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;" /> ');
);
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.
Yes you can, have you considered adding another ajax call in your success function
– Dale
Sep 6 '18 at 10:43