Laravel 4 jQuery的Ajax请求 [英] Laravel 4 jquery Ajax Request

查看:168
本文介绍了Laravel 4 jQuery的Ajax请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来Laravel 4.我有一个页面中,我有3个标签(基本上是大的可点击的div)来加载不同的用户信息。我希望做的是,我希望能够点击这些标签,让jQuery的Ajax请求,带回的局部视图和更新页面的一部分与该局部视图。我希望能够做到这一点每一个标签。

I am new to Laravel 4. I have a page within which I have 3 tabs(basically big clickable divs) to load the different user information. What I would like to do is that I would like to be able to click on those tabs,make jquery ajax request,bring back a partial view and update a part of page with that partial view. I would like to able to do that for every tab.

我得到的点击事件firing.I也尝试过不同的code来完成Ajax请求。出于某种原因,没有任何反应。我不知道如果我失去了一些东西在route.php。任何人都可以请给我就怎么做,有些code?或可能是一些其他的想法?

I got the click event firing.I also tried different code to accomplish ajax request. For some reason, nothing happens. I do not know if I am missing something in route.php. Could anyone please give me some code on how to do that? or may be some other idea?

我这样做是::

Route.php

Route.php

Route::post('userInfo','UserController@showInfo');

jqueryAjax:

jqueryAjax:

$("divtoUpdatePartialView").click(function(){

$.ajax({
  type: "POST",
  url:Not Sure,
  data: { id: userId }
}).done(function( msg ) {
  alert( msg );
});

}

我试图用基地址也是如此,但没有任何反应。我有我的母版页中声明的Ajax库。能否请你帮我或者给我一些其他的想法?

I tried using Base Url too, but nothing happens. I have an ajax library declared on my master page. Could you please help me or give me some other ideas?

非常感谢您的回答。我试过这种方式,这是我...

Thank you very much for your answer. I tried that way, this is what I have...

Route.php:

Route::get('user_Profile/userInfo', 'UserController@getshow');

AJAX的:

The ajax:

var  userId='1';

$.ajax({
    type: "POST",
    url: 'user_Profile/userInfo',
    data: { id: userId }
}).done(function( msg ) {
    alert( "the messageis "+msg );
});


My userController::

public function getshow()
    {
           return "No ajax";
    if (Request::ajax()) {

        return "yeahhhh";
    $html=View::make('user.userProfile')->nest('partial', 'user.userInfoPartial')-        >with('title',$title)->render();


}
}

当我直接访问该网页,我收到没有AJAX,但是当我尝试了Ajax的方式,没有什么happens.Could你看,我缺少的是什么?

When I directly access the page I receive "No ajax", but when I try the ajax-way,nothing happens.Could you see what I am missing??

再次感谢大家的帮助。

推荐答案

网​​址应该是路径/模式你用你的路线并且在这种情况下,它

The url should be the path/pattern you have used in your route and in this case it's

userInfo

AJAX

$.ajax({
    type: "POST",
    url: 'userInfo',
    data: { id: userId }
}).done(function( msg ) {
    alert( msg );
});

此外,确保这一点,你可以直接使用从浏览器的地址栏访问页面

Also, make sure that, you can directly access the page from your browser's address bar using

http://yourdomain.com/userInfo

这篇关于Laravel 4 jQuery的Ajax请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆