gpt4 book ai didi

php - 将 JavaScript 确认中的值传递给 Codeigniter Controller

转载 作者:行者123 更新时间:2023-11-29 08:38:53 25 4
gpt4 key购买 nike

我是 JavaScript 和 Codeigniter 新手。我想知道如何将 JavaScript 确认(是/否)传递给 Codeigniter Controller 。

例如我有一个链接

更新所有记录。(如何链接这个?)。

用户单击它后,会弹出一条消息,显示您确定吗?。如果是,那么它将被传递到 Controller /模型并进行更新,如果不是,它将保留在同一页面上。

或者有人可以教我其他方法吗?

最佳答案

你用什么?单选按钮?如果是,只需在单选按钮标签上方添加表单标签即可。

这是示例

<form name = "yesno" action = "<?php site_url('check/yesorno') ?>" method = "post">
<input type = "radio" name = "yesorno" value = "yes" onclick = "this.form.submit()">Yes
<br>
<input type = "radio" name = "yesorno" value = "no" onclick = "this.form.submit">No
</form>

/*Note:
Form name = name of form
action = destionation url (site_url(yourController/yourFunction))
method = post/get
onclick = javascript event (will execute the code when user click)
this.form.submit() = javascript dom, means submit the your form when specified event executed*/

如果你想使用ajax,请编写代码

//first->create the object
//for chrome, firefox, etc
if(window.XMLHttpRequest)
{
xmlhttp = new XMLHttpRequest();
}
//fro ie, etc
else
{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}

//to get response from php
xmlhttp.onreadystatechange = function()
{
if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
//your code here
}
}

//open connection
xmlhttp.open("GET","../project_php/login.php",true);
xmlhttp.send();

/*Note:
GET -> method
2nd paramater(../project_php/login.php) -> destination url
3rd parameter -> true or false (use true!)

on "your code here" comment, add your code if response from php successfully received.
*/

关于php - 将 JavaScript 确认中的值传递给 Codeigniter Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14413256/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com