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,
Nigel
$(function() {
//twitter bootstrap script
$("button#submit").click(function(){
$.ajax({
type: "POST",
url: "add_events.php",
data: $('form#add-event-form').serialize(),
success: function(msg){
$("#thanks").html(msg)
$("#modal-new-event").modal('hide');
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(){
alert("failure");
}
});
$('#calendar').fullCalendar('unselect');
});
});
2
Answers
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:
That is assuming that the text field has
title
as id. If you havename="title"
instead ofid="title"
, then:You could just grab the
title
from where you posted it, provided it has an id, say, if it was a text input like:You can grab it from anywhere with
Another option would be to return the title posted in a json and use it in your success callback like