Re: How to use jQuery ajax instead of XMLHttpRequest

See all posts See thread Reply

Re: How to use jQuery ajax instead of XMLHttpRequest new!
by colin, 11 years, 2 months ago
You should check if you have something meaningful in $_SERVER, $_REQUEST, etc... Also, check the log produced by the class.

I don't have time to try using jQuery for the upload, but your example seems quite too simple compared to the code samples given on these links.

I would suggest not using jQuery for the upload case (as in this case, jQuery complicates the code), or else trying out the code samples providing in the link above.Reply
Re: How to use jQuery ajax instead of XMLHttpRequest new!
by Malinga, 11 years, 2 months ago
you have mentioned " xhr.send(f)" in your ajax request. "f" means file object.?

i'm passing 'file name'. it can be passed through header. ( X-File-Name )

can you explain "xhr.send(f)" on your js script? why you pass 'f'?Reply
Re: How to use jQuery ajax instead of XMLHttpRequest new!
by colin, 11 years, 2 months ago
I am not too sure which f you are talking about.

The basic JS code for the XHR upload is:
// xhr example
var xhr_file = null;
document.getElementById("xhr_field").onchange = function () {
  xhr_file = this.files[0];
  xhr_parse(xhr_file, "xhr_status");
}
document.getElementById("xhr_upload").onclick = function (e) {
  e.preventDefault();
  xhr_send(xhr_file, "xhr_result");
}

As I said before, if you want to use jQuery, it is more complicated, as you need access the XHR object, which jQuery doesn't publicly allow.

Again, please check the 5 top results here, these links explain how to make it work with a jQuery form, and provide code samples, as well as interesting discussions about different jQuery versions and browser compatibility.Reply
Re: How to use jQuery ajax instead of XMLHttpRequest new!
by Malinga, 11 years, 2 months ago
@Colin,

Happy to say this... i could upload an image asynchronusly without using XMLHttpRequest.

use this amazing plugin. http://malsup.github.io/jquery.form.js

example:
//reservation approval count
$('#formAddBanner').ajaxForm({
  url:'upload.php',
  data:{addBanner:1},
  type:'POST',
  success:    function(data) { 
    alert(data); 
  }
});

Again thank you very much for the code.Reply