为什么它不起作用。我试图通过一些参数发生按钮的onclick时调用php文件。它会一直执行到jsfile.js中的alert语句为止。之后,ajax部分将无法执行..帮帮我..预先感谢..
main.html
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="jsfile.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
</head>
<body>
<button onclick="cart(0)"> hi </button>
<p id="disp"></p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
jsfile.js
function cart(id1)
{
var id=id1;
alert("enterd "+id);
document.getElementById("disp").innerHTML ="hi";
$.ajax({
url:"/add.php ",
type:"POST",
data:{
item_id: id,
},
success:function(response) {
//document.getElementById("total_items").value=response;
document.getElementById("disp").innerHTML =response;
},
error:function(){
alert("error");
}
});
}
Run Code Online (Sandbox Code Playgroud)
add.php
<?php
if(isset($_POST['item_id']) && !empty($_POST['item_id'])){
//if(count($_POST)>0)
echo "success";
exit();
}
?>
Run Code Online (Sandbox Code Playgroud) 我正在使用 rails 6。我按照“ https://www.learnenough.com/ruby-on-rails-4th-edition-tutorial ”中的教程开发了一个示例 rails 应用程序。但是,当我尝试运行“rails test”时,它抛出Bad file descriptor (Errno::EBADF) error。
我的 GEM 文件:
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.5.0'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.0.0'
# Use Puma as the app server
gem 'puma', '~> 3.11'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 4.0'
# Turbolinks makes navigating your web application faster. Read more: …Run Code Online (Sandbox Code Playgroud)