开发者

jQuery - What's the error here?

开发者 https://www.devze.com 2023-02-27 08:44 出处:网络
I\'m working with jQuery\'s .get() function and I\'m having a very weird problem using it. Here\'s the front end...

I'm working with jQuery's .get() function and I'm having a very weird problem using it.

Here's the front end...

<body>

<button title="minor">Minor Armor</button>
<br /><br />
<button title="medium">Medium Armor</button>
<br /><br />
<button title="major">Major Armor</button>
<br /><br />
<center>
    <div id="printout" style="border: 1px black dotted; height: 300px; width: 300px;">
    </div>
</center>

</body>

Here's the function I'm trying to use...

$("button").click(function () {
            var v = "dnd_specific_armor_" + $(this).attr("title");
            alert(v + " was pressed.");
            $.get("randloot.php", { "table" : v }, function(data) {
                if(data.roll != 0) {    
                    alert(data.roll);
                    alert(data.armor);
                    alert(data.price);
                    $('#printout').text("Roll - " + data.roll
                                        "\nArmor - " + data.armor
                                        "\nPrice - " + data.price);
                }
                else
                    $('#printout').text("Oops");
            }, "json");
        });

The buttons simply will not respond to clicks. The alert window does not pop up, I get nothing in my div box. N开发者_开发知识库o response at all.

The funny thing though, is that if I take out the .get() portion and use just this...

$("button").click(function () {
            var v = "dnd_specific_armor_" + $(this).attr("title");
            alert(v + " was pressed.");             
        });

Then it works fine.

I'm trying to work within Firefox 4 and I've tried pulling up the Java Console (which doesn't even show) and the Error Console (which isn't reporting any errors). So I can't figure out what's going wrong at all.

Any suggestions?


Your code contains syntax errors.

                $('#printout').text("Roll - " + data.roll
                                    "\nArmor - " + data.armor
                                    "\nPrice - " + data.price);

should be

                $('#printout').text("Roll - " + data.roll +
                                    "\nArmor - " + data.armor +
                                    "\nPrice - " + data.price);

Btw, checking the error console would have shown this, too - that's usually a good thing to do before asking here. ;)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号