duanhao7786
2014-08-25 13:39
浏览 135
已采纳

将输入值传递给ajax获取Laravel

I am fairly new to Laravel and ajax in general, what I am trying to implement is to pass the value of an input field through an ajax get request. My request looks like this:

function getInfo() {

        $.ajax({
            url: "info",
            dataType: "json"
        }).success(function(data){
            $('#result').append(JSON.stringify(data));
        }).fail(function(){alert('Unable to fetch data!');;
        });
    }
    $('#infoSubmit').click(getInfo);

I have setup a route for my function in laravel that works like this public/info/Variable <--

When I add a variable after info/ I get the data for that variable (e.g profile name)

I need to pass this variable from an inputfield to ajax request to something like this: url: "info/+$inputfieldVariable"

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • douzhi9635 2014-08-25 13:44
    已采纳

    Change:

    url: "info",
    

    TO:

    url: "info/" + $('input-field-selector').val(),
    

    Not sure about the correctness of your JS code: Shouldn't you be using done instead of success?

    评论
    解决 无用
    打赏 举报
查看更多回答(1条)

相关推荐 更多相似问题