通过AJAX将canvas.toDataUrl()发送到php [英] Sending a canvas.toDataUrl() to php via AJAX

查看:191
本文介绍了通过AJAX将canvas.toDataUrl()发送到php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过AJAX将canvas.toDataUrl()发送到php页面。

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

这是我的尝试:

JavaScript代码:

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();
}

这个很好用,
,但是当我使用canvas.toDataUrl时()无效!为什么?

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

还有另一种将canvas.toDataUrl()发送到php的方法吗?

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

谢谢

推荐答案

已解决

问题是我试图通过GET发送大数据,
我通过通过POST发送相同(大)数据解决了它
POST比GET复杂一点。

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

以下是使用POST通过AJAX发送数据的方法:

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

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

我在链接中使用了代码,并且可以正常工作与我在一起
遇到相同问题的任何人,请参考上面的链接,并使用POST代替GET

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

感谢大家

这篇关于通过AJAX将canvas.toDataUrl()发送到php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆