通过Ajax发送带有额外参数的表单数据吗?

时间:2019-04-24 11:11:28

标签: javascript jquery ajax

我正在尝试将带有表单数据以及其他一些参数的发布请求发送到我的Codeigniter控制器。这是我正在使用的代码。

function onSignIn(googleUser) {
    console.log('onto the function');
    var profile = googleUser.getBasicProfile();

    var google_name = profile.getName();
    var google_image = profile.getImageUrl();
    var google_email = profile.getEmail();
    console.log('got the details');
    console.log('submitting');
    var title = ('#title').val();
    var message = ('#message').val();
    $.ajax({
        type: "POST",
        url: 'http://localhost/review/submit',
        data: {
            title,
            message,
            'google_name': google_name,
            'google_email': google_email,
            'google_image': google_image,
        },
        success: function () {
            alert('fuck');
        }
    });
}

我不断收到$ is not defined,但我不知道为什么,因为删除$会给我#title.val() is not a function

1 个答案:

答案 0 :(得分:1)

确保您为jquery引用提供了正确的代码路径

在您的代码的头部添加以下CDN链接

https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js

相关问题