skip to Main Content

I am trying to use the a parameter from data returned from an ajax call in the success return function of that ajax call.

As per code below, I submit of my modal an ajax call is sent to add_events.php with a $_POST[‘title’] paramater. I want the resultant ‘title’ string to be used in the on success function (msg) as ‘var title’ so it can then be used in the renderEvent that follows.

It seems possible, but I can’t find the correct syntax to do this 🙁 Any assistance would be appreciated.

Thank you,

$(function() {
        //twitter bootstrap script
                type: "POST",
                url: "add_events.php",
                data: $('form#add-event-form').serialize(),
                success: function(msg){

                    var title = 'This is not the correct title'; //WANT THIS TO BE THE RETURN VALUE FOR title THAT WAS POSTED TO PHP FILE 
                    var eventData = { title: title };
                    $('#calendar').fullCalendar('renderEvent', eventData, true); // stick? = true
                error: function(){



  1. I don’t know if I’m getting well what you want but I’m gonna take the risk. If what you want is to grab the value that you sent to your php page on the server, then you do this:

    var title = $('#title').val()

    That is assuming that the text field has title as id. If you have name="title" instead of id="title", then:

    va title = $('input[name="title"]').val();
    Login or Signup to reply.
  2. You could just grab the title from where you posted it, provided it has an id, say, if it was a text input like:

    <input id="title">AWESOME TITLE</input>

    You can grab it from anywhere with

    $('#title').val(); // "AWESOME TITLE"

    Another option would be to return the title posted in a json and use it in your success callback like

    {"msg":"your message", "title":"your title"}
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top