Cannot make jsFiddle example work

喜欢而已 提交于 2020-01-26 04:17:28

问题


I will like to have the same functionality found in here: http://jsfiddle.net/jhruh/2/ on my website.

I don't understand why if I copy all the things I do not get the same functionality. The steps I have done are:

  1. Copied the HTML
  2. Added the jquery library ( <script src="http://code.jquery.com/jquery-1.8.3.js"></script> in the head of the html I copied on step 1
  3. added a script tag as the last child of the body tag containing the jsFiddler code.
  4. Added the jquery $(function(){}) on top of JavaScript code.

In other words I now have:

<!DOCTYPE html>
<html>
<head>
    <title>jQM Complex Demo</title>
    <meta name="viewport" content="width=device-width" />

    <!-- Step 2 -->
    <script src="http://code.jquery.com/jquery-1.8.3.js"></script>

    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
    <script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
</head>
<body>
    <div data-role="page" id="index">
        <div data-role="header">
            <h1>
                XML Parsing demo</h1>
        </div>
        <div data-role="content">
            <ul data-role="listview" data-inset="true" id="cars-data">
            </ul>
        </div>
    </div>
    <div data-role="page" id="cars">
        <div data-role="header">
            <a data-role="button" data-transition="none" data-theme="a" href="#index">Back</a>
            <h1>
            </h1>
        </div>
        <div data-role="content">
            <ul data-role="listview" data-inset="true" id="car-data">
            </ul>
            <img src="" width="100%" style="height: auto;" id="car-img" />
        </div>
    </div>

    <!-- Step 3 -->
    <script>

        // <!-- Step 4 // do stuff after DOM has loaded -->
        $(function () {

            $('#index').live('pagebeforeshow', function (e, data) {
                $('#cars-data').empty();
                $.ajax({
                    type: "POST",
                    url: "InvalidUrlCreatedOnPurpose",
                    dataType: "xml",
                    data: {
                        xml: "<cars><car><name>TOYOTA</name><country>JAPAN</country><pic>http://1call.ms/Websites/schwartz2012/images/toyota-rav4.jpg</pic><description>Toyota has announced that it will recall a total of 778,000 units that may have been manufactured with improperly-tightened nuts on the rear suspension.</description></car></cars>"
                    },
                    success: function (xml) {


                        var xmlstr = (new XMLSerializer()).serializeToString(xml);
                        alert(xmlstr);

                        alert(xml);
                        ajax.parseXML(xml);

                    },
                    error: function (request, error) {
                        alert('Remember to remove this message once it works!');
                        var x = "<cars><car><name>TOYOTA</name><country>JAPAN</country><pic>http://1call.ms/Websites/schwartz2012/images/toyota-rav4.jpg</pic><description>Toyota has announced that it will recall a total of 778,000 units that may have been manufactured with improperly-tightened nuts on the rear suspension.</description></car></cars>";
                        ajax.parseXML(x);
                    }
                });
            });

            $("#cars").live('pagebeforeshow', function () {
                $("#cars div[data-role='header'] h1").html(carObject.carName);
                $('#car-data').empty();
                $('#car-data').append('<li>Car Type:<span> ' + carObject.carName + '</span></li>');
                $('#car-data').append('<li>Car Country:<span> ' + carObject.carCountry + '</span></li>');
                $('#car-data').append('<li>Car Description:<span> ' + carObject.description + '</span></li>');
                $('#car-data').listview('refresh');
                $('#car-img').attr('src', carObject.img);

            });

            var ajax = {
                parseXML: function (result) {
                    $(result).find("car").each(function () {
                        carObject.carName = $(this).find('name').text();
                        carObject.carCountry = $(this).find('country').text();
                        carObject.img = $(this).find('pic').text();
                        carObject.description = $(this).find('description').text();

                        $('#cars-data').append('<li><a href="#cars"><img src="' + carObject.img + '" title="sample" height="100%" width="100%"/><h3>Car type:<span> ' + carObject.carName + '</span></h3><p>' + carObject.description + '</p></a></li>');
                    });
                    $('#cars-data').listview('refresh');
                    $('#index').append('<div data-role="footer" data-position="fixed"><h1>Dynamicaly added footer</h1></div> ');
                    $('#index [data-role="content"]').append('<fieldset data-role="controlgroup"><legend>Choose:</legend><input type="radio" name="radio" id="radio1" value="1" checked="checked" /><label for="radio1">option 1</label></fieldset>');
                    $('#index').trigger('pagecreate');
                }
            }

            var carObject = {
                carName: '',
                carCountry: '',
                img: '',
                description: ''
            }

        });

    </script>
</body>
</html>

The page behaves different why? I know that jsFiddler can simulate an ajax call using the url 'echo' but I simulated an error on purpose hoping I could get the same results on my website.

Edit

I changed the image source for: http://cdn1.iconfinder.com/data/icons/sleekxp/Google%20Chrome.png

I updated jsFiddler the new link is: http://jsfiddle.net/jhruh/3/ and I canot make it work still.


回答1:


Line 33, Column 74: Bad value for attribute src on element img: Must be non-empty. Syntax of IRI reference: Any URL. For example: /hello, #canvas, or http://example.org/. Characters should be represented in NFC and spaces should be escaped as %20.



来源:https://stackoverflow.com/questions/14537486/cannot-make-jsfiddle-example-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!