As part of my project, I am required to provide my client a functionality that can verify user's input Social Security Number by using CBSV's web service. I've read the documents in CBSV's website, including Consent Based Social Security Number Verification Service (CBSV) | Web Services, but can't see any example of using jQuery and AJAX. Anyway, here's what I've done so far.
In the php file that contains the form, I have this piece of jquery code to register event of the SSN textbox after user enters value in it.Code:function checkSSN(ssnfield,fnamefield,lnamefield,dobfield) { var ssn = $("#"+ssnfield).val(); var first_name = $("#"+fnamefield).val(); var last_name = $("#"+lnamefield).val(); var middle_name = get_Middle_name(first_name, last_name); var date_of_birth = $("#"+dobfield).val().replace("/", ""); var age = getAge($("#"+dobfield).val()); var minor = (age >= 16)?"N":"Y"; $.ajax ({ url: "https://ws.ssa.gov/CBSVWS/services/CBSVServices?wsdl", type: "POST", dataType: "xml", data: {"ssn":ssn, "firstName":first_name, "middleName":middle_name, "lastName":last_name, "dateOfBirth":date_of_birth, "minor":minor}, contentType: "text/xml; charset=\"utf-8\"", success: function (data) { console.log("Success:"); }, error: function (xhr, st, er) { console.log("Request error:" + er); } }); } function getAge(dateString) { var today = new Date(); var birthDate = new Date(dateString); var age = today.getFullYear() - birthDate.getFullYear(); var m = today.getMonth() - birthDate.getMonth(); if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) { age--; } return age; } function get_Middle_name(fname,lname) { if ((typeof fname == 'string' || fname instanceof String) && (typeof lname == 'string' || lname instanceof String)) { fname = fname.replace(/\s+/, ""); lname = lname.replace(/\s+/, ""); var middle_name = ""; var full_name = fname + " " + lname; var count_words = countWords(full_name); if(count_words >= 3) { var array_of_names = full_name.split(" "); for(var i=1; i < array_of_names.length - 1 ; i++) { middle_name += array_of_names[i]; } } else { middle_name = ""; } return middle_name; } else return ""; } function countWords(s){ s = s.replace(/(^\s*)|(\s*$)/gi,"");//exclude start and end white-space s = s.replace(/[ ]{2,}/gi," ");//2 or more space to 1 s = s.replace(/\n /,"\n"); // exclude newline with a start spacing return s.split(' ').length; } function _webSSNVerification_forSignUp() { checkSSN("personalInfo_personalSSN", "personalInfo_personalFName", "personalInfo_personalLName", "personalInfo_personalBirthday"); }
And these are the messages that I got in the console.logCode:$("#personalInfo_personalSSN").each(function(){ this.addEventListener("blur", _webSSNVerification_forSignUp, true); });
My question is, what did I do wrong? How can I call the CBSV webservice to check user's input SSN?OPTIONS ws.ssa.gov/CBSVWS/services/CBSVServices?wsdl 500 (Error) jquery-1.7.2.min.js:4
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'localhost'; is therefore not allowed access. jquery-1.7.2.min.js:4
send jquery-1.7.2.min.js:4
f.extend.ajax jquery-1.7.2.min.js:4
checkSSN common.js:519
_armSSNVerification_forSignUp common.js:584
Please help. Thank you.



Reply With Quote

Bookmarks