Gabriel - As the post on the Tableau Software forums warns, you do NOT want to ask for a trusted ticket using only (client-side) JavaScript/AJAX. Doing so will get you into lots of trouble, essentially opening Tableau Server up so that anyone can request a ticket for anyone else. Implement that way, and you'll shortly be out of a job :)
You can use AJAX to call a server-side PHP function, even though doing so is kind of a kludge. However, since the page will live on a single server, trusted by you, you're safe.
Here's what your code might look like:
First, modify the tableau_trusted.php, adding a function or two:
function generateTicket()
{
$ticket= get_trusted_ticket_direct($_POST['server'], $_POST['user'], $_POST['targetsite']);
echo $ticket;
}
if ($_POST['toDo'] == 'generateTicket') {
generateTicket();
}
Here's how you might call the page:
// variables to feed trusted ticket retrieval
var phpScript = "http://someserver/tableau_trusted.php",
userName = "someuser",
serverURL = "tableauserverlocation";
// variable to hold trusted ticket
var incomingTicket;
$.post(phpScript, {
toDo: 'generateTicket',
user: userName,
server: serverURL,
targetsite: ''
}, function(response) {
// do something with response (the ticket) right here
incomingTicket = response;
});
I'm guessing you're trying to re-use one of the Tableau samples vs. writing your own code, and that's fine. BUT, the gymnastics you're putting yourself through may be more troublesome than writing a simple web service (or windows service, or whatever) to do this work for you, then calling it from your portal's page. That would be a cleaner design pattern, anyway.
Good luck!