简体   繁体   English

通过 ajax 调用将参数传递给 controller 中的方法

[英]Pass parameter to method in controller via ajax call

I'm sure this is probably easy but I'm having the hardest time finding the answer!我敢肯定这可能很容易,但我很难找到答案!

I have a method in my controller defined as:我的 controller 中有一个方法定义为:

public function update_news($newsID = NULL) { 
//updates news article
}

I'm trying to use that method as the url in an ajax call for example:我正在尝试将该方法用作 ajax 调用中的 url ,例如:

     jQuery.ajax({
            url: "manage/project/update_news(5)",
            data: formData,
            cache: false,
            mimeType: "multipart/form-data",
            dataType: 'json',
            contentType: false,
            processData: false,
            type: 'POST',
...

I get the error POST https://dev.vmc.w3.uvm.edu/xana/manage/project/update_news(5) 400 (Bad Request)我收到错误 POST https://dev.vmc.w3.uvm.edu/xana/manage/project/update_news(5) 400 (Bad Request)

How do I pass the parameter to the controller function?如何将参数传递给 controller function?

I don't know if you work with a framework but I think the url in your ajax could be:我不知道您是否使用框架,但我认为 ajax 中的 url 可能是:

manage/project/update_news/5

or或者

manage/project/update_news?newsID=5

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM