I am trying to customise the jquery chat bot using the sample plugin present in https://www.jqueryscript.net/form/engage-audience-conversational-chatty.html.
I am using the following code:
var tags=[];
$.ajax({
type: "POST",
/*method type*/
url: "sample.jsp",
dataType: "text",
data: "usrname=" + $('#uname').val(),
async: false // To push values to an array
}) //ajax
.done(function(data) {
alert(data); // it displayed all the content which is needed for the array correctly
tags.push(data);
})
.fail(function(f) {
alert("Chatbot Module fetch failed!!");
});
I am retrieving 'data' as a String from java method:
if I use following line directly into javascript function it is working fine:
function addArr() {
tags.push({type: 'input', tag: 'text', name: 'converse', 'chat-msg': 'Hi Welcome!!'},);
}
but if I try to push the string in to array it is not working. I am framing the string content as given below:
// java code:
result = "{type: 'input', tag: 'text', name: 'converse', 'chat-msg': 'Hi Welcome!!'},"
return result;