javascript - Jquery ajax function not being called -
i have web page fill's form data based on json data sent web service. once form ready submitted function called takes form data turns xml-formatted string parses xml becomes valid xml object. problem happens, once data turned xml post data web service database can updated. using $.ajax() function post data, neither success nor error function within ever called. lead's me believe ajax function never being called or run. below code snippets:
submit button form:
<input type="submit" name="submitbutton" id="submitbutton" value="submit" onclick="postdata()"/>
postdata function:
function postdata() { //gathering 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 table data 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 purpose of example, web service name var properid = 'somedata'; xmldoc = $.parsexml( xmlstring ); $xml = $( xmldoc ); //this function believe never run neither alerts below 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"); } }); }
addfield function (just know when it's called in postdata()):
function addfield(name, value) { // add single element , value value = value.replace(/&/g, '&').replace(/</g,'<').replace(/>/g,'>'); return '<' + name + '>' + value + '</' + name + '>'; }
Comments
Post a Comment