I am writing a chat application and want to get settings for all subsequent AJAX calls in the first chat call.

I set the default jQuery AJAX settings:

```
jQ.ajaxSetup({
  url : 'chat.php',
  contentType: 'application/json'
  dataType : 'json',
  type : 'post'
});

```

Then I pass the action to return a JSON object containing the data to connect to the specific chat.

```
jQ.ajax({
  data: {
    'action' : 'connect'
  },
  success: function (data) {
    if (data.success) {
    // set user ID and chat ID for all subsequent ajax calls
      if (data.partner) {
      // start fetching data to listen for messages
      } else {
      // keep checking for partner
      }
    } else {
    //  chat connect failed
    }
  }
});

```

If the chat is created and the user is connected to a chat partner, Every 0.2 seconds I fetch data from the server like so:

```
setTimeout(fetchData, 200);
function fetchData(){
  jQ.ajax({
    data: {
      'action' : 'fetch'
    },
    success: function (data) {
      if (data.success) {
        // update messages
      }
      setTimeout(fetchData, 200);
  });
}

```

I also have AJAX functions to post data and disconnect from the chat, and basically they will all need to have the same chat credentials as set by the initial 'connect' action.

What would be the best way to achieve this?