jquery - Send JSON using $.Ajax() with a POST method -
i trying send json object using $.ajax() in jquery post method, pure html page ,to datapower endpoint.the response header in fire bug gives me"internal server error",please can 1 tell me doing wrong here : http/1.1 500 error x-backside-transport: fail fail content-type: text/xml connection: close
my jquery code looks :
$(document).ready(function () { $('#btn_submitcallback').click(function () { //add values need api object var objcallbackdata = new object; var d = new date(); var dat = d.getdate(); var mon = d.getmonth() + 1; var year = d.getfullyear(); var todaydate = dat + "/" + mon + "/" + year; alert("inside submit callback"); //build object objcallbackdata.store_code = "poo726"; //$('#sel_title').val(); objcallbackdata.title = $('#sel_title').val(); objcallbackdata.first_name = $('#txt_firstname').val(); objcallbackdata.last_name = $('#txt_surname').val(); objcallbackdata.house_number = $('#txt_houseno').val(); objcallbackdata.street = $('#txt_streetname').val(); objcallbackdata.city = $('#txt_city').val(); objcallbackdata.post_code = $('#txt_postcode').val(); objcallbackdata.email = $('#txt_email').val(); objcallbackdata.phone_number = $('#txt_phone').val(); objcallbackdata.project_type = "bathroom"; objcallbackdata.callbacktime_morning = "y"; objcallbackdata.callbacktime_afternoon = "y"; objcallbackdata.callbacktime_evening = "n"; objcallbackdata.callbacktime_weekend = "n"; objcallbackdata.callbacktime_weekday = "y"; objcallbackdata.helparea_measuring = "y"; objcallbackdata.helparea_designing = "n"; objcallbackdata.helparea_usingspaces = "n"; objcallbackdata.helparea_services = "n"; objcallbackdata.helparea_productinfo = "n"; objcallbackdata.status = "o"; objcallbackdata.date = todaydate; // alert(objcallbackdata.date); //turn object in json string var myjson = json.stringify(objcallbackdata); alert(myjson); $.ajax({ type: 'post', url: 'http://xb629050-s1.uk.b-and-q.com:9340/api/callback', contenttype: 'application/json; charset=utf-8', data: myjson, datatype: 'json', success: function () { alert("good"); }, error: function (xhr, status) { switch (status) { case 404: alert('file not found'); break; case 500: alert('server error'); break; case 0: alert('request aborted'); break; default: alert('unknown error: ' + xhr.statustext); } } }); }); });
ajax not support cross domain request. need use jsonp method this.
also see this
Comments
Post a Comment