weixin_33701251 2016-04-19 13:26 采纳率: 0%
浏览 37

有关数据传输的错误

I am trying to transfer data to python through ajax.. And the error comes like this..

Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.

Here is my html code(js and ajax are included here itself) :

<html>

<head>
    <style>
        .html,
        .css {
            height: 175px;
            border-bottom: 1px solid #cfd6d9;
            overflow-y: scroll;
            background-color: #f3f5f6;
            padding-left: 20px;
        }
    </style>
</head>

<body>

    <div class="container">

        <div class="user-container user-html">
            <h3>HTML</h3>
            <div>(Don't put html, head and body tag)</div>

            <div class="editor margin-top-20 html" contenteditable="true"></div>
        </div>

        <div class="user-container user-css">
            <h3>CSS</h3>
            <div>(Write css styles)</div>
            <div class="editor margin-top-20 css" contenteditable="true"></div>
        </div>

        <div class="user-container">
            <h3>Preview</h3>
            <div>(Write css styles)</div>
            <iframe class="user-preview margin-top-20" src="user-file.html"></iframe>
        </div>

    </div>

    <div class="container text-center">
        <button onclick="create_file();">Submit</button>
    </div>


    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.3/jquery.js" type="text/javascript"></script>

    <script type="text/javascript">
        function create_file() {

            var userhtml = $(".user-html .editor").text();

            var usercss = $(".user-css .editor").text();

            var finalHTMl = "<!DOCTYPE html><html><head><style>"+usercss +"</style></head>" +
                "<body>" + userhtml + "</body></html>";

            //Ajax start
            $.ajax({
                url: "test1.py"
                , type: 'POST'
                , data: {
                    'htmldata': finalHTMl
                    , css: usercss
                }
                , success: function (result) {
                    $('.user-preview').attr('src', $('iframe').attr('src'));
                }
            });
            //Ajax End

        }
    </script>

</body>

</html>

And this is my python code :

def index(req):
        postData = req.form
        json = str(postData['htmldata'].value)
        print(json)

Can u guys please tell me where i am wrong

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
    • ¥20 西门子S7-Graph,S7-300,梯形图
    • ¥50 用易语言http 访问不了网页
    • ¥50 safari浏览器fetch提交数据后数据丢失问题
    • ¥15 matlab不知道怎么改,求解答!!
    • ¥15 永磁直线电机的电流环pi调不出来
    • ¥15 用stata实现聚类的代码
    • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
    • ¥20 docker里部署springboot项目,访问不到扬声器
    • ¥15 netty整合springboot之后自动重连失效