Kohana 3 jQuery / AJAX请求无效

时间:2022-10-13 15:09:10

I am trying to post some data to a controller in Kohana 3 using the jQuery AJAX method. I seem to have an issue with the data not getting to where I want it to be. I want the data to go to the /application/classes/controller/stock.php file where the file will process the data. I can't seem to figure this one out. Hopefully someone can help. My jQuery ajax call is:

我试图使用jQuery AJAX方法将一些数据发布到Kohana 3中的控制器。我似乎有一个问题,数据没有达到我想要的地方。我希望数据转到/application/classes/controller/stock.php文件,文件将在该文件中处理数据。我似乎无法想出这个。希望有人可以提供帮助。我的jQuery ajax调用是:

        $.ajax({
            type: 'POST',
            url: 'add_stock',
            data: { 'links': 'link_array' }
            });

'add_stock' is the name of the action within the controller. I didn't know what else to try. I've also tried '.' and './' hoping that would be right but it's not. In Firebug, although it says the request was 200 OK, I see that the "RESPONSE" is "Failed to load source for: http://localhost/ddm/v2/stocks/add_stock" and my script in my controller which grabs the data isn't working. Here is that code in case it helps:

'add_stock'是控制器中操作的名称。我不知道还有什么可以尝试的。我也试过'。'并且'./'希望这是正确的,但事实并非如此。在Firebug中,尽管它说请求是200 OK,我看到“RESPONSE”是“无法加载源:http:// localhost / ddm / v2 / stocks / add_stock”和我的脚本在我的控制器中抓住了数据不起作用。这是代码,以防它有帮助:

$links = $_POST['links'];

$link_obj = Jelly::factory('link')
    ->set('stock', $stock->id)
    ->set('links', $links);

    $link_obj->save();

I think that the problem is that I'm giving the ajax call the ROUTE and not the actual page it needs to deliver the POST data to. I just can't figure it out here.

我认为问题在于我将ajax调用给ROUTE,而不是将POST数据传递到的实际页面。我在这里无法弄明白。

Any help?

有帮助吗?

1 个解决方案

#1


2  

rename your controller method "add_stock" to "add_stock_action"

将控制器方法“add_stock”重命名为“add_stock_action”

you can also see what exactly went wrong if you klick the link where firebug tells you 200.

如果你点击firebug告诉你200的链接,你也可以看到到底出了什么问题。

#1


2  

rename your controller method "add_stock" to "add_stock_action"

将控制器方法“add_stock”重命名为“add_stock_action”

you can also see what exactly went wrong if you klick the link where firebug tells you 200.

如果你点击firebug告诉你200的链接,你也可以看到到底出了什么问题。