以下のjavascriptにて、tweetloadを実行させたのですが、
通信1までlogは行くのですが、
$(window).bind('bottom',function(){
文以降が実行されず、
tweetload内のajaxの表示の部分がでません。
bottom部分をコメント文にした場合は、
予定通り、ajaxの表示が働いている状況です。
また、他のjqueryのプラグインvalidateも追加しましたが、
messageが表示されず。
どちらもエラーはでないのですが、
動作しません。
jqueryは、3.1.1
追記
jqueryを2.2.4に変更しました。
cakephp 2.xです。
javascript
1var user_id; 2var my_id; 3 4$(function(){ 5 //15秒ごとに読み込み 6 tweet_load(); 7 console.log('sucess'); 8 setInterval("tweet_load()", 15000); 9 console.log('sucess4'); 10}); 11 12$(document).on('click','button',function(event){ 13 if(!confirm('本当に削除しますか?')){ 14 /* キャンセルの時の処理 */ 15 return false; 16 }else{ 17 event.preventDefault(); 18 $.ajax({ 19 type:'POST', 20 url: '/cakephp/users/json_data', 21 dataType: 'json', 22 cache : false, 23 data : {id : $(this).val()}, 24 timeout:10000, 25 success: function(data) { 26 //console.log(user_id+' '+my_id+' '+$('textarea').val()+' '+time); 27 console.log('delite_success'); 28 tweet_load(); 29 }, 30 error: function(XMLHttpRequest, textStatus, errorThrown) { 31 alert('error'); 32 } 33 });} 34 }); 35 36$(document).on('click','div.submit',function(event) { 37 console.log('validate_start'); 38 $('form').validate({ 39 rules: { 40 textarea: { 41 required: true, 42 maxlength: 140 43 } 44 }, 45 messages :{ 46 textarea:{ 47 required: "空白です。", 48 maxlength:"140文字以内で入力して下さい。" 49 } 50 } 51 }); 52 53 if (!$('form').valid()) { 54 console.log('validate_error'); 55 return false; 56 } 57 console.log('validate_end'); 58 event.preventDefault(); 59 $.ajax({ 60 type:'POST', 61 url: '/cakephp/users/json_data', 62 dataType: 'json', 63 cache : false, 64 data : {'tweet_id': user_id ,'name': my_id , 'tweet' : $('textarea').val()}, 65 timeout:10000, 66 success: function(data) { 67 $('textarea').val(""); 68 //console.log(user_id+' '+my_id+' '+$('textarea').val()+' '+time); 69 console.log('sucess'); 70 tweet_load(); 71 }, 72 error: function(XMLHttpRequest, textStatus, errorThrown) { 73 alert('error'); 74 } 75 }); 76}); 77 78 79function tweet_load(){ 80 81 var end_flag = 0; //最後のページまでいったら1にして次から読み込ませない 82$('div.loading').append('loading...'); 83 $(window).bottom({proximity: 0.5}); //proximityを0.5にするとページの50%までスクロールするとloadingがはじまる 84 console.log('通信1'); 85 $(window).on('bottom',function(){ 86 console.log('通信2'); 87 var obj = $(this); 88 if (!obj.data("loading")) { 89 obj.data("loading", true); 90 91 $('#loading').append('loading...'); //画面にloading...と表示 92 setTimeout(function() { 93 $('#loading').remove(); 94$.ajax({ 95 type:"POST", 96 url: '/cakephp/users/json_data', 97 dataType: 'json', 98 cache : false, 99 timeout: 10000}) 100 .fail(function(){ 101 //通信失敗時の処理 102 alert('通信失敗'); 103 }) 104 .done(function(data){ 105 alert('通信'); 106 user_id = data.user_id; 107 my_id = data.my_id; 108 var i=0; 109 console.log('sucess_jsondata'+i); 110 $("#output").empty(); 111 for(i in data.json_data){ 112 $("#output").append('<a href='+data.json_data[i].Tweet.name+'>'+data.json_data[i].Tweet.name+"</br>"); 113 var tweet =data.json_data[i].Tweet.tweet; 114 tweet =tweet.replace(/\r?\n/g, '<br>'); 115 tweet =tweet.replace(/((http|https|ftp):\/\/[\w?=&.\/-;#~%-]+(?![\w\s?&.\/;#~%"=-]*>))/g, '<a href="$1">$1</a> '); 116 $("#output").append(tweet+"</br>"); 117 $("#output").append(data.json_data[i].Tweet.tweettime+"</br>"); 118 //console.log(i); 119 if(data.my_id==data.json_data[i].Tweet.name){ 120 $("#output").append('<button type="button" name="delite" id="delite" value='+data.json_data[i].Tweet.id+'>削除</button></br>'); 121 } 122 $("#output").append("</br>"); 123 } 124 })}, 1500); 125 } 126 }); 127 $('html,body').animate({ scrollTop: 0 }, '1'); 128}; 129
form部分も追加
cakephpのctpです。
php
1<?php 2echo $this->Html->script('https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js'); 3echo $this->Html->script('jquery.bottom-1.0'); 4echo $this->Html->script('jquery.validate'); 5echo $this->Html->css('index');?> 6 7 <?php 8 echo $this->Form->create('Tweet'); 9 echo nl2br($this->Form->textarea('tweet', array('cols'=>100, 'rows'=>4,'required' => false,'error'=>false))); 10 echo $this->Form->hidden('tweet_id',array('value'=> $user['id'])); 11 echo $this->Form->hidden('name',array('value'=> $user['username'])); 12 echo $this->Form->submit('投稿',array(/*'onclick'=>'index',*/'name' => 'submit')); 13 echo $this->Form->end(); 14endif; 15?> 16 <h3>ホーム</h3> 17 <div id="output"> 18 <div id="delite"></div> 19 <div class="loading"></div> 20 </div>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/10/26 00:28
2016/10/26 12:26
2016/10/26 14:04
2016/10/26 14:37
2016/10/26 14:55 編集
2016/10/26 15:03
2016/10/26 15:13
2016/10/26 15:52
2016/10/26 16:12
2016/10/27 14:43 編集