I have Jquery code
$('#add_companies').click( function(e) {
var form_id = '#'+ $(this).parents('form').attr('id');
var result = do_submit(form_id);
console.log(result);
});
The code get the data from the form given by the form id and do the submit, using
do_submit()
do_submit() function
function do_submit(form_id) {
var url = $(form_id).attr("action");
var ajax_result = false;
// Submit form using ajax
ajax_result = $.ajax({
type: "POST",
url: url,
data: $(form_id).serialize(),
dataType: 'json',
success: function(result) {
return result;
},
error: function(result) {
// code here
});
},
});
return ajax_result;
} // End do_submit()
after the successful submit, it return an object stored in result
with this data
Object {readyState: 1}
abort: function(a)
always: function()
complete: function()
done: function()
error: function()
fail: function()
getAllResponseHeaders: function()
getResponseHeader: function(a)
overrideMimeType: function(a)
pipe: function()
progress: function()
promise: function(a)
readyState: 4
responseJSON: 1
responseText: "1"
setRequestHeader: function(a,b)
state: function()
status: 200
statusCode: function(a)
statusText: "OK"
success: function()
then: function()
__proto__: Object
when I try to get the value of result
responsetext in this format
result.responseText
console says
undefined
how to properly get the responseText?