【问题标题】:Javascript isn't working with Jquery and ajax [closed]Javascript 不适用于 Jquery 和 ajax [关闭]
【发布时间】:2014-04-24 14:27:18
【问题描述】:
<div class="RegisterFrame">
                <form method="post" id="form" action="registeration.php" class="reg" enctype="multipart/form-data">
                    <input type="file" class="fileChooser" name="img">
                    <div class="uploadimg" name="imgUploader"><img src="" name='IDpic' class="IDpic"></div><br>
                    <text>Username</text><input type="text" class="textBox" name="user"><br>
                    <text>Password</text><input type="password" class="textBox" name="pass"><br>
                    <text>re-enter your password</text><input type="password" class="textBox" name="repass"><br>
                    <text>e-mail</text><input type="text" class="textBox" name="email"><br>
                    <text>re-enter your e-mail</text><input type="text" class="textBox" name="reemail"><br>
                    <button class="Con" type="submit">Done O.o</button><button class="Res" type="button">reset</button>
                </form>

            </div>

============================================

脚本代码:

$("#form").submit(function(e) {
        e.preventDefault();
//        alert('test');
        data = new FormData($('#form')[0]);
//                console.log('Submitting');
        $.ajax({
            type: 'POST',
            url: 'registeration.php',
            data: data,
            cache: false,
            contentType: false,
            processData: false,
            success: function(result) {
                alert(result);
                //PS: the result gives the correct full path yet the image doesn't change
                document.getElementsByClassName('.IDpic').src=result;

            }
        });
    });

【问题讨论】:

  • 编辑您的问题。解释问题是什么(在代码块格式之外)。你写“用户名”、“密码”等,但你没有解释它是什么。很难阅读您的问题。根据您的“P.S.”,您的问题是“结果给出了正确的完整路径,但图像没有改变。”问题不应隐藏在代码中。
  • 问题是什么?
  • 为什么是 document.getElementsByClassName('.IDpic').src=result;不工作
  • 错误出现在路径中...... C:\wamp\www\playAround\uploads 是给定的路径,它应该只是“\uploads”:)

标签: javascript jquery html ajax


【解决方案1】:
.getElementsByClassName('.IDpic').

我猜类名不包含点 - 这应该是 .getElementsByClassName('IDpic').

另外,既然你使用的是 jQuery,不妨这样做

$('.IDpic').attr('src', result);

【讨论】:

  • 或者$('.IDpic')如果OP想要使用jQuery...
  • $('.IDpic').attr('src', 结果); //仍然不工作:.
猜你喜欢
  • 2011-12-18
  • 2023-03-03
  • 1970-01-01
  • 2013-04-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-16
  • 1970-01-01
相关资源
最近更新 更多