简体   繁体   English

jQuery AJAX方法返回语法错误:意外标识符

[英]JQuery AJAX Method Returns a Syntax Error: Unexpected Identifier

I have been wrestling with a weird error for quite some time now. 我已经为怪异的错误挣扎了一段时间了。 I want to believe that this is one of those errors where the solution will just slap me in the face, but we shall see. 我想相信这是那些错误,解决方案只会让我耳光,,但我们会看到的。 Here's the code: 这是代码:

    var images = {};
    // Set Image Gallery
    function setImageGallery() {
        // Get Product JSON
        $.ajax({
            url:"JSONimages.php"
            data:{
                "table":"belts"
            }, // Firefox says this } is missing... but it's here.
            success:function (data) {
                images = $.parseJSON(data);
                alert("Got Images!");
            }
        });
    }

And here's the code snippet being pulled from an AJAX Request: 这是从AJAX请求中提取的代码段:

<script type="text/javascript">
    setImageGallery($("select[name=imageGallerySelect]").val().toLowerCase());
</script>

<h2>Edit Image Gallery</h2>
<p>Select Gallery: <select name="imageGallerySelect" onchange="setImageGallery()">
    <option>Belts</option>
    <option>Gallery</option>
    <option>Home</option>
    <option>Hybrid</option>
    <option>IWB</option>
    <option>Knives</option>
    <option>OWC</option>
</select></p>
<form action="">
    <p>Image:<br><input type="file" name="image"></p>
    <p>Price:<br><input type="text" name="price"></p>
    <p>Description:<br><textarea name="description"></textarea></p>
    <p><input type="submit" value="Save"></p>
    <div id="thumbnails"></div>
</form>

Now, in the process of debugging, I changed the $.AJAX() method to directly set the value of "table" for my PHP (which outputs JSON) script to "belts". 现在,在调试过程中,我更改了$ .AJAX()方法,以将我的PHP(输出JSON)脚本的“ table”的值直接设置为“ belts”。 I'm getting mixed results. 我得到的结果好坏参半。 Chrome is telling me it's an error from the JQuery Script itself. Chrome告诉我,这是JQuery脚本本身的错误。 Firefox says there's a missing "}" at the spot where I put the little comment in the first code sample. Firefox表示我在第一个代码示例中加了一点注释的地方缺少一个“}”。 I've toyed with the script with zero luck. 我以零运气玩弄了剧本。 It's errors like this that let me know I have a lot to learn :/ The anonymous success function never gets run and the alert doesn't pop up, of course. 像这样的错误让我知道我有很多东西要学习:/当然,匿名成功功能永远不会运行,并且警报不会弹出。 I'm hoping this is a stupid error and that I'm making a newb mistake here :) 我希望这是一个愚蠢的错误,并且我在这里犯了一个新手错误:)

Oh god, I saw it as soon as I submitted the question. 哦,天哪,我提交问题后就看到了。 The function setImageGallery() does not accept any variables, but I pass it a string! 函数setImageGallery()不接受任何变量,但我将其传递给字符串!

You are missing , after the url parameter: 您缺少 url参数之后:

 url:"JSONimages.php", //<-------------- this comma you missed
            data:{
                "table":"belts"
            },

Wait, no. 等一下 That was a stupid mistake, but I'm still getting an error. 那是一个愚蠢的错误,但我仍然遇到错误。 Help? 救命? Firefox error reads: "SyntaxError: missing } after property list". Firefox错误显示为:“ SyntaxError:属性列表后缺少}”。 Chrome insists that the error is on Line 2 of the JQuery Library. Chrome坚持认为该错误在JQuery库的第2行上。 I don't know that either of those errors are very useful. 我不知道这些错误中的任何一个都非常有用。 The } is there. }在那里。 The JQuery library is flawless. JQuery库是完美的。 I want to believe that I'm somehow screwing up the $.ajax() call, but it worked when I used it elsewhere. 我想相信我在某种程度上搞砸了$ .ajax()调用,但是当我在其他地方使用它时,它起作用了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM