1

M having problem with getting resposnse from the server.M using Jquery Ajax I want to upload a file using ajax.But the follwing lines of codes are not working page1:

<script language="javascript" src="jquery-1.7.1.js"/></script>
<script language="javascript" src="jquery.form.js"/></script>
<script language="javascript">
$(document).ready(function(){
  $('#photoimg').change(function(){
    var fd=new FormData();
    $.ajax({
      type:'POST',
      url:'NewuploadScript.php',
      data:fd,
      contentType: 'application/x-www-form-urlencoded',
      async:true,
      cache:false,
      processData: true,
      success:function Result(data2) {
        document.write(data2);
      }
    }); 
  });
});
</script>
<form> 
<input type="file"  id="photoimg" name="file" multiple>
<input type="submit" id="BtnSbmt" value="Upload"/>
</form>

Pag2:

<?php
echo $name=  basename($_FILES['photoimg']['name']);
echo $size=  basename($_FILES['photoimg']['size']);
?>

when I run the codes jquery display the following error:

Uncaught TypeError: Illegal invocation
jQuery.extend.param.addjquery-1.7.1.js:7601
buildParamsjquery-1.7.1.js:7658
jQuery.extend.paramjquery-1.7.1.js:7621
jQuery.extend.ajaxjquery-1.7.1.js:7467
(anonymous function)ImageUploader.php:18
jQuery.event.dispatchjquery-1.7.1.js:3256
jQuery.event.add.elemData.handle.eventHandlejquery-1.7.1.js:2875
dotoree
  • 2,983
  • 1
  • 24
  • 29
kishor
  • 35
  • 3
  • See http://stackoverflow.com/questions/9048358/illegal-invocation-error-in-ajax-jquery-1-7-1 – dotoree Mar 27 '12 at 10:25
  • have you get it working .. http://stackoverflow.com/questions/5140156/illegal-operation-on-wrappednative-prototype-object – dan_l Nov 20 '12 at 11:47

2 Answers2

0

It's hard to tell what the error message means exactly without seeing what comes back in your Ajax exchange. Your PHP code should not read

echo $var_name = ...

because that is an assignment. Try the following...

<?php
    echo basename($_FILES['photoimg']['name']);
    echo basename($_FILES['photoimg']['size']);
?>

Or just

print_r($_FILES);
Pete
  • 1,289
  • 10
  • 18
0

for starters edit :

success:function (data2) {
        document.write(data2);
      }

Maybe the problem is related with FormData see this

Community
  • 1
  • 1
dotoree
  • 2,983
  • 1
  • 24
  • 29
  • @kishor function needs to be anonymous, remove `Result` – dotoree Mar 27 '12 at 10:57
  • Good point, but the error comes before that. I've tried to run the code and I'm getting "Illegal operation on WrappedNative prototype object" before I even submit. I think Kishor needs to copy and paste the example code from the jquery.form plug-in site. – Pete Mar 27 '12 at 11:16