Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/472.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用Ajax发送查询字符串和会话信息_Javascript_Jquery_Ajax_Session_Asp.net Ajax - Fatal编程技术网

Javascript 使用Ajax发送查询字符串和会话信息

Javascript 使用Ajax发送查询字符串和会话信息,javascript,jquery,ajax,session,asp.net-ajax,Javascript,Jquery,Ajax,Session,Asp.net Ajax,我使用Ajax创建评论,但它不起作用,我不确定问题出在哪里。我想这可能是因为我在读UserID和VideoID 我将UserID保存在会话中,而videoID保存在查询字符串中。 我看错了吗?!如果是,我如何阅读 以下是我的js代码: <script type="text/javascript"> $(document).ready(function () { $('#btnPost').click(function (e) {

我使用Ajax创建评论,但它不起作用,我不确定问题出在哪里。我想这可能是因为我在读UserID和VideoID

我将UserID保存在会话中,而videoID保存在查询字符串中。 我看错了吗?!如果是,我如何阅读

以下是我的js代码:

        <script type="text/javascript">

         $(document).ready(function () {

        $('#btnPost').click(function (e) {

            $.ajax({

                url: "Ajax/ProcessAddComment.aspx",
                data: {
                    commenttext: $('.txtcomment').val(),
                    videoid: Request.QueryString["d"],

            userid: $.session.get('UserID')
                },
                success: function (data) {
                    alert(data);

                },
                error: function () {

                }

            });



        });


        $.ajax({
            url: "Ajax/ProcessFindComment.aspx",
            data: { videoid: Request.QueryString["id"] },
            success: function (data) {
                 // Append to the bottom
                // of list while prepend
                // to the top of list

                $('.postlist').html(data);
            },
            error: function () {
                alert('Error');
            }
        });




    });

$(文档).ready(函数(){
$('#btnPost')。单击(函数(e){
$.ajax({
url:“Ajax/ProcessAddComment.aspx”,
数据:{
commenttext:$('.txtcomment').val(),
videoid:Request.QueryString[“d”],
userid:$.session.get('userid')
},
成功:功能(数据){
警报(数据);
},
错误:函数(){
}
});
});
$.ajax({
url:“Ajax/ProcessFindComment.aspx”,
数据:{videoid:Request.QueryString[“id”]},
成功:功能(数据){
//附在底部
//预结束时的列表列表列表
//上榜
$('.postlist').html(数据);
},
错误:函数(){
警报(“错误”);
}
});
});
我假设您正在使用获取和设置会话

我想你的问题是:
Request.QueryString

尝试使用以下JS函数从querystring中获取一个值,而不是该值:

function (key) {
    if (!key) return '';
    key = key.replace(/[*+?^$.\[\]{}()|\\\/]/g, "\\$&"); // escape RegEx meta chars
    var match = location.search.match(new RegExp("[?&]" + key + "=([^&]+)(&|$)"));
    return (match && decodeURIComponent(match[1].replace(/\+/g, " "))) || '';
};

注意:您可以使用开发者窗口中的网络选项卡(在大多数浏览器中为F12)查看Ajax数据。那里的错误控制台应该告诉您是否有JavaScript错误,网络选项卡应该告诉您Ajax请求和响应中有什么内容。

我实际上没有使用任何插件,我正在使用Visual Studio Asp.net