jQuery .find() on data from .ajax() call is returning “[object Object]” instead of div

Trying to find div element with id=”result” in returned data from .ajax() using .find(). Unfortunately, alert(result) doesn’t return div#result. Here is my code: $.ajax({ url: url, cache: false, success: function(response) { result = $(response).find(“#result”); alert(response); // works as expected (returns all html) alert(result); // returns [object Object] } }); Answer To answer your question specifically, … Read more

What is the best way to learn backbone.js? Any other alternatives? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for … Read more

purpose of .bind(this) at end of ajax callback?

From the reactjs tutorial, what’s the purpose of having .bind(this) at the end of the ajax callback? Does code work correctly without it? data: JSON.stringify({text: text}), success: function (data) { this.setState({data: data}); }.bind(this), Answer It ensure’s this will be the correct object inside the callback. See Function.prototype.bind(). An alternative specific to react is to do: … Read more

Pure JavaScript code for HTTP Basic Authentication?

Where can I find reference code that implements a HTTP Basic Authentication client in pure JavaScript, suitable for AJAX? Extra points for code, or pointers to code, that can be used independent of JS toolkits like YUI. No points for Java, Flash/Flex, PHP frameworks, etc. Answer The five-parameter version of the XMLHttpRequest.open method allows you … Read more

How to upload a file using jQuery.ajax and FormData

When I use XMLHttpRequest, a file is correctly uploaded using FormData. However, when I switch to jQuery.ajax, my code breaks. This is the working original code: function uploadFile(blobFile, fileName) { var fd = new FormData(); fd.append(“fileToUpload”, blobFile); var xhr = new XMLHttpRequest(); xhr.open(“POST”, “upload.php”, true); xhr.send(fd); } Here is my unsuccessful jQuery.ajax attempt: function uploadFile(blobFile, … Read more