/    Sign up×
Community /Pin to ProfileBookmark

Jquery ajax function not being called

I have a web page which fill’s form data based on some json data sent from a web service. Once the form is ready to be submitted a function is called which takes all the form data turns it into a xml-formatted string then parses the xml so it becomes a valid xml object. This is where the problem happens, once this data is turned into an xml I would like to post this data back to the web service so the database can be updated. However using the $.ajax() function to post this data, neither the success nor error function within are ever called. This lead’s me to believe the ajax function is never being called or run. Below are the code snippets:

submit button for form:

[code=html] <input type=”submit” name=”submitbutton” id=”submitbutton” value=”Submit” onclick=”postData()”/>[/code]

postData function:

[CODE] function postData()
{
//gathering all inputs
var cb = document.getElementById(‘paymentList’);
var selected_cb = cb.options[cb.selectedIndex].text;
var pguid = getParameterByName(‘guid’);
var xmlString = ‘<string>’ +
addField(‘approver’, $(‘#approver’).val()) +
addField(‘companyName’, $(‘#companyName’).val()) +
addField(’emailAddress’, $(‘#emailaddress’).val()) +
addField(‘address1’, $(‘#address1’).val()) +
addField(‘address2’, $(‘#address2’).val()) +
addField(‘city’, $(‘#city’).val()) +
addField(‘province’, $(‘#province’).val()) +
addField(‘country’, $(‘#country’).val()) +
addField(‘postalCode’, $(‘#postalcode’).val()) +
addField(‘phoneNumber’, $(‘#phone’).val()) +
addField(‘paymentMethod’, selected_cb);

//gathering all table data now
xmlString+='<contractData>’;
$(‘#table tbody tr:has(img[src=”images/checkmark.png”])’).each(function() {
xmlString += ‘<contract>’ + addField(‘vendorPart’, $(‘td:eq(1)’, this).text()) +
addField(‘description’, $(‘td:eq(2)’, this).text()) +
addField(‘price’, $(‘td:eq(3)’, this).text()) +
addField(‘quantity’, $(‘td:eq(4) input’, this).val()) + ‘</contract>’;
});

xmlString += ‘</contractData></string>’;

//hard coded var for purpose of this example, as web service name will be
var properid = ‘somedata’;

xmlDoc = $.parseXML( xmlString );
$xml = $( xmlDoc );

//this function I believe is never run as neither alerts below are posted
$.ajax({
type: “POST”,
url: “http://www.webservice.com/service.asmx/sendMeMyData”,
data: {properdata:properid, xml: $xml},
dataType: “text”,
success: function() {

alert(“posted”);
},
error: function ()
{
alert(“error”);
}
});

}[/CODE]

addField function (just so you know what it does when it’s called in postData()):

[CODE] function addField(name, value) { // Add a single element and value
value = value.replace(/&/g, ‘&amp;’).replace(/</g,’&lt;’).replace(/>/g,’&gt;’);
return ‘<‘ + name + ‘>’ + value + ‘</’ + name + ‘>’;
}[/CODE]

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @MannyG spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...