このコードを機能させるのに多くの問題があります:
<script type = "text/javascript">
jQuery(document).ready(function($){
$('#submitbutton').click(function(){
var email=document.getElementById('emailadd').value;
var password=document.getElementById('pass').value;
$.ajax({
type: "POST",
url: "/wp-content/themes/roots-master/login.php",
data: {emailaddress:'email', password:'password'},
dataType: "text",
success:function(response){
alert("success");
}
});
});
});
</script>
$.ajax 関数をコメントアウトすると、javascript は正常に動作します (アラートでテストしました)。ただし、 $.ajax の部分は機能していないようです。誰か提案はありますか?
コードを次のように変更すると、javascript も機能しないように見えます。
$('#submitbutton').click(function(){
var email=document.getElementById('emailadd').value;
var password=document.getElementById('pass').value;
$.ajax({
alert(password);
});
});
私はワードプレスを使用しているので、jqueryへのリンクを頭に入れませんでした。代わりに、以下を functions.php に追加すると、jquery が機能し始めました。
wp_deregister_script('jquery');
wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery /1/jquery.min.js', false, '1.9.1', false);
wp_enqueue_script('jquery');
更新: 何らかの理由で、$.ajax の後にアラートを配置すると、機能します!
jQuery(document).ready(function($){
$('#submitbutton').click(function(){
var email=document.getElementById('emailadd').value;
var password=document.getElementById('pass').value;
$.ajax({
dataType: "html",
type: "POST",
evalScripts: true,
url: "/wp-content/themes/roots-master/login.php",
data: {emailaddress:'email', password:'password'},
dataType: "text",
success:function(){
alert("success");
}
});
alert("testing");
});
});
これがなぜなのか誰か知っていますか?