I am trying to learn how to display data from an Ajax response with jquery
This was is what is returned to the console
Object {type: "success", message: "Your message has been sent, thank you.", record: Object}
record: Object
account_number: "1234567812345678"
balance: "1234"
bank_name: "test name"
customer_id: "12345"
id: 49
monthly: "123456"
This is the current script that brings it to the console:
jQuery(document).ready(function($) {
$('form.quform').Quform({
successStart: function (response) {
console.log(response);
This is what I have tried but it does not work, it stops the AJAX from working when you add the extra closing bracket at the bottom, but it does nothing if you take it off:
jQuery(document).ready(function($) {
$('form.quform').Quform({
successStart: function (response) {
var r = response.record;
var html = '<li>Acct#: ' + r.account_number + '</li><li>Balance: ' + r.balance + '</li><li>Bank: ' + r.bank_name + '</li><li>Customer#: ' + r.customer_id + '</li>';
$("#ulID").html(html);
}
});
});
Please note I have added <div id="ulID"></div>
into the page because I think that is what I need to display it
I must admit that i am unfamiliar with the way you use ajax to get a 'response' Are you querying a webservice? And i am not familiar with the Quform plugin either, you should specify that in your question that you are using a plugin.
But i will try and help you anyways. Since your question asked for displaying data from an Ajax response, i will assume that you are querying a webservice and try and help you out with that assumption Here is the code to call a webservice with Ajax without using a plugin.
$.ajax({
url: 'webservice url',
type: "POST",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
alert('Success!');
$('.ulID').text('response was: ' + data.d)
},
failure: function (msg) {
alert('an error occured');
}
});
The url is offcourse the link to the webservice, and the data contains any parameters that the webservice require.
This is to my knowledge the correct way to use Ajax to query a webservice.
if you want help with getting help with the code you already have i suggest removing Ajax from the question and replacing it with Quform. But to be honest, Ajax calls in JQuery are so easy that unless you plan on using that plugin for something else i'd drop the plugin.
btw: this setup expects the webservice to support json
i hope this helps
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments