How do I pass request data into the Complete event in JQuery.ajax -


i'm trying write code send jquery ajax post request , i'm having trouble emulating examples see.

i want send post request third party website, , call function write responsetext div, pretty basic stuff.

function addsearch(searchterm) {     $.ajax({         accept: "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",         url: "http://www.website.com",         contenttype: "application/x-www-form-urlencoded",         beforesend : function (xhr) {             xhr.setrequestheader("acceptlanguage", "en-us,en;q=0.5");             xhr.setrequestheader("acceptencoding", "gzip, deflate");         },         type: "post",         data: createbody(searchterm),         complete: dostuffoncomplete(xhr, status)     }); }  function dostuffoncomplete(xhr, status) {     var response = xhr.responsetext;     $("#content").append(response); } 

i'm following other basic examples i've seen on here. while no errors 'xhr' variable in beforesend event, getting error in complete when script called, saying xhr undefined.

i'm sure i'm messing simple, not having experience jquery, ajax, or javascript in general i'm not sure what.

i expect you're having problem fact url third party.

try adding datatype: 'jsonp' after type: "post".

also, rather using 'complete', use 'success' , 'error':

[...]     type: "post",     datatype: "jsonp",     data: createbody(searchterm),     success: function(data) {         console.log(data);     }     error: function(data) {         console.error(data);     } }); 

Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

java - SmsManager sending message more than one -