通过AJAX将canvas.toDataUrl()发送到php

I am trying to send a canvas.toDataUrl() to a php page via AJAX.

Here's is my try:

JavaScript code:

function showUser() {
str = "url="+canvas.toDataUrl();

     if (window.XMLHttpRequest) {
             // code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest();
     } else { // code for IE6, IE5
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
       }
    xmlhttp.onreadystatechange=function() {
    if (xmlhttp.readyState==4 && xmlhttp.status==200) {
        document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
   }
    xmlhttp.open("GET","file.php?"+str,true);
    xmlhttp.send();
}

php:

<?php
   $url = $_GET['url'];
   echo "$url";
?> 

The code above doesn't seem to be working, although I did the exact same thing but with a String value instead, like the following:

    function showUser() {
str = "url=12345";

     if (window.XMLHttpRequest) {
             // code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest();
     } else { // code for IE6, IE5
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
       }
    xmlhttp.onreadystatechange=function() {
    if (xmlhttp.readyState==4 && xmlhttp.status==200) {
        document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
   }
    xmlhttp.open("GET","file.php?"+str,true);
    xmlhttp.send();
}

This one works fine, but when I use canvas.toDataUrl() it doesn't work !? why?

Is there another way to send canvas.toDataUrl() to php?

Thanks

I reccommend trying the javascript encodeURIComponent() function like this:

str = "url="+encodeURIComponent(canvas.toDataUrl());

The thing is, that dataurl contains symbols like "/" so it might get falsely interpreted. Let me know if that works.

SOLVED

The problem was that I was trying to send Large data through GET, I solved it by sending the same (large) data through POST POST is a little more complex than GET though

Here's how to send data via AJAX using POST:

http://www.javascriptkit.com/dhtmltutors/ajaxgetpost2.shtml

I used the code in the link and it works fine with me anyone having the same problem please refer the link above and use POST instead of GET

Thanks everybody