weixin_33709219 2015-07-31 05:21 采纳率: 0%
浏览 35

jQuery ajax中的url生成

$(document).ready(function () {
    $(".linkDelete").click(function () {
        var userid = $(this).attr("id");
        console.debug("saurabh userid", userid);

        var url = "/delete?id=" + userid;
        var s = "SpringHibernateAnnotations";
        console.debug("saurabh url", url);
        $.ajax({
            url: s + "/delete?id=" + userid,
            success: function (data) {
                $('#result').html(data);
            }
        });
    });
});

i have this jquery ajax function which is generating this url GET http://localhost:8080/SpringHibernateAnnotations/SpringHibernateAnnotations/delete?id=253 404 (Not Found) instead it should generate http://localhost:8080/SpringHibernateAnnotations/delete?id=253 404 and if i remove var s= "SpringHibernateAnnotations"; and keep my url in ajax method as url : "/delete?id="+userid, it generates http://localhost:8080/delete?id=253 because of which i am not able to enter into application.So how can i generate this proper url http://localhost:8080/SpringHibernateAnnotations/delete?id=253

  • 写回答

1条回答 默认 最新

  • weixin_33690367 2015-07-31 05:24
    关注

    Add / before the url for base path. -

    var s= "/SpringHibernateAnnotations";
    

    If / is not present at the start then it will be considered as relative path. The url will be - http://localhost:8080/SpringHibernateAnnotations/delete?id=253

    评论

    报告相同问题?

    悬赏问题

    • ¥15 设计程序,利用函数getCharacterCnt,实现求解出str所指字符串中指定字符的个数,并返回此值。
    • ¥15 设计程序,实现管理30个学生5门课程的成绩,功能模块要求如下。
    • ¥15 B660主板安装xp系统老是出现错误怎么办
    • ¥15 定义过的变量报错未定义
    • ¥15 如何在EXCEL某单元格中查找是否存在另一列中的内容。
    • ¥50 非对称加密(相关搜索:密码学)
    • ¥15 关于非编程寻迹小车的分析
    • ¥15 java导出EXCEL这里已经执行成功了,但是流浪器没有下载
    • ¥15 帮我把代码改的能正常运行就行
    • ¥50 有限元修正、模型修正、最小二乘法,详细步骤