Hi all,
I have in my js file:
function sendDataToPhp()
{
theUrl = 'myfile.php';
params = '';
params += 'function=sendData';
params += '&myfield='+someVariableForMyField;
$.ajax ({
url: theUrl,
data: params,
type: "POST",
async:false,
success: function (data, textStatus)
{
}
});
}
Then in myfile.php
if (isset($_REQUEST['function']))
{
$function = $_REQUEST['function'];
}
switch ($function) {
case 'sendData':
//code
break;
default:
//code
}
With this I’m sending the code flow to the sendData case of the switch.
Now Inside the success, in the ajax() I need to send the code flow to the default case of the switch. How can I do that?
Thanks a million!
The way Switch works is if there isn’t a matching CASE then it goes to DEFAULT case … so perhaps you can provide
function=IdontExistFunctionin your ajax call … OR if there is piece of code in DEFAULT you want to run then best to separate it and make it a function so that you can call from anywhere as required.BTW – There is GOTO statement available too – not sure if you can make use of it in your case http://php.net/manual/en/control-structures.goto.php ?