Reputation: 1285
I have a conditional function in my controller for what it has been posted from the view. Therefore, I want to send the respond or a callback to the view when the data is submitted.
For some reason, I don't want to use ajax or iframe to handle this callback.
I am expecting a pure javascript combined with php to do this:
The sketch might be like this:
<script>
var callbackFromController = <?php echo $callbackFromController;?>
if(callbackFromController == "Love")
{
alert("This is Love");
}
else if(callbackFromController == "Wealth")
{
alert("This is Wealth");
}
else if(callbackFromController == "Healt")
{
alert("This is Healt");
}
else
{
alert("This is Life");
}
</script>
But I want to get the $callbackFromController as soon as the button is submitted (Like ajax success respond)
Once again, I don't want to use ajax or iframe for this one.
The reason I don't want to use ajax is I don't want to pass the url as well as the data in the ajax post.
[Updated]
Based on the answer I've got from this question, it is said that I have to use either ajax or iframe.
If I have to use ajax, can I do this without passing the url and/or data post or get?
Upvotes: 2
Views: 69
Reputation: 26696
PHP writes the value out before the page is served to the browser.
If that's the case, then PHP can not write it out after a button has been clicked on the page, unless you are reloading the page.
...an alternative might be to dynamically create a link to a new script page (which is actually a .php page, but served with an application/javascript MIME type), which contains both your script logic and your PHP writing...
This is a horrible solution, but it's technically possible; you just have to do the wrong thing at every level (client, apache web-server and php web-app) layer.
Upvotes: 2
Reputation: 1273
You are unable to interact with PHP without reloading the page or using AJAX request or iframe, as you suggested.
Upvotes: 0