大家早上好, 我的脚本有问题。 我使用outlook API,我的目标是将我的电子邮件存储在我的数据库中。 到现在为止还挺好。然后,我希望能够将我的电子邮件移动到其他表格。我希望能够单击按钮将我的电子邮件存储在所需的表中。 我设法做了一张桌子。插入进展顺利。当我尝试添加表时出现问题。 当我插入第一个表时,它会自动将邮件复制到另一个表中。 我不明白,我必须忘记一些事情。
我的剧本:
我的观看文件:
<div id="onglets" class="row justify-content-around">
<button type="submit" class="btn btn-primary col-2" onclick="show_menu('inbox')" > <a href="#inbox">Inbox </a></button>
<button type="submit" class="btn btn-primary col-2" onclick="show_menu('etat')" >Facebook</button>
<button type="submit" class="btn btn-primary col-2" onclick="show_menu('zone')" > Fun </button>
<button type="submit" class="btn btn-primary col-2" onclick="show_menu('chat'),btn_display_urgent()" > Urgent </button>
<button type="submit" class="btn btn-primary col-2" onclick="show_menu('coffre'),btn_display_a_faire()" > A faire </button>
<button type="submit" class="btn btn-primary col-2" onclick="show_menu('rapport')" > Archive </button>
</div>
<script id="msg-list-template">
<div class="row">
<div class="col-lg-12 option_test">
{{#each messages}}
<div class="emailBody">
<h3 id="msg-from" class="list-group-item-heading from_1">{{this.from.emailAddress.name}}</h3>
<h4 id="msg-subject" class="test list-group-item-heading subject_1">{{this.subject}}</h4><button type="submit" class="btn btn-primary btn-sm col-1" onclick="btn_urgent(this)" >urgent</button><button type="submit" class="btn btn-primary btn-sm col-1" onclick="btn_a_faire(this)" >A faire</button>
<p id="msg-received" class="list-group-item-heading text-muted received_1"><em>Received: {{formatDate this.receivedDateTime}}</em></p>
<div id="post1" class="azerty">
<p id="msg-bodyPreview" class="list-group-item-text text-muted azerty bodypreview_1"><em>{{this.bodyPreview}}</em></p>
<div class="demasquer">
<p id="msg-uniqueBody" class="body_1"><em>{{{this.uniqueBody.content}}}</em></p>;
<p id="msg-uniqueBody" class="body_2 hidden"><em>{{this.uniqueBody.content}}</em></p>;
</div>
</div>
</div>
}
}
{{/each}}
</div>
</div>
</script>
&#13;
带有我的AJAX请求的文件:
window.onload = function(){
console.log("********************TEST_INSERT*********************");
for($i = 0; $i <= 4; $i++){
console.log("after for");
console.log($i);
$input = document.getElementsByClassName('from_1')[$i].textContent;
$sub = document.getElementsByClassName('subject_1')[$i].textContent;
$recei = document.getElementsByClassName('received_1')[$i].textContent;
$preview = document.getElementsByClassName('bodypreview_1')[$i].textContent;
$body_2 = document.getElementsByClassName('body_2')[$i].textContent;
console.log("*********************");
console.log($input);
console.log($sub);
console.log($recei);
console.log($preview);
console.log($body_2);
console.log("*********************");
}};
function btn_a_faire(item){
console.log("**********************");
console.log("******ajax a faire************");
console.log("**********************");
var $thisInput = $(item).closest(".emailBody").find(".from_1")[0].innerHTML;
var $thisSub = $(item).closest(".emailBody").find(".subject_1")[0].innerHTML;
var $thisRecei = $(item).closest(".emailBody").find(".received_1 em")[0].innerHTML;
var $thisPreview= $(item).closest(".emailBody").find(".bodypreview_1 em")[0].innerHTML;
var $thisBody = $(item).closest(".emailBody").find(".body_2 em")[0].innerHTML;
$.ajax({url: '../../wp-content/plugins/game_plugin/process_general_2.php',
type: 'POST',
data: {info: 'a_faire', input: $thisInput, sub: $thisSub, recei: $thisRecei, preview: $thisPreview, body : $thisBody},
success: function() {
console.log("OK");
}
});
}
function btn_urgent(item){
console.log("**********************");
console.log("******ajax URGENT************");
console.log("**********************");
var $thisInput = $(item).closest(".emailBody").find(".from_1")[0].innerHTML;
var $thisSub = $(item).closest(".emailBody").find(".subject_1")[0].innerHTML;
var $thisRecei = $(item).closest(".emailBody").find(".received_1 em")[0].innerHTML;
var $thisPreview = $(item).closest(".emailBody").find(".bodypreview_1 em")[0].innerHTML;
var $thisBody = $(item).closest(".emailBody").find(".body_2 em")[0].innerHTML;
$.ajax({url: '../../wp-content/plugins/game_plugin/process_general.php',
type: 'POST',
data: {info: 'insert_to_db', input: $thisInput, sub: $thisSub, recei: $thisRecei, preview: $thisPreview, body : $thisBody},
success: function() {
console.log("OK");
}
});
}
&#13;
我发出SQL请求的文件:
$info = $_POST['info'];
$thisInput= $_POST['input'];
$thisRecei= $_POST['recei'];
$thisSub= $_POST['sub'];
$thisPreview= $_POST['preview'];
$thisBody= $_POST['body'];
// Then call the function
insert_to_db($thisInput, $thisSub, $thisRecei, $thisPreview, $thisBody);
function insert_to_db($thisInput, $thisSub, $thisRecei, $thisPreview, $thisBody){
global $wpdb;
$wpdb->insert(
'test_insert', //table name
array(
'id' => '',
'from_mail' => $thisInput,
'subject' =>$thisSub,
'recei' => $thisRecei,
'preview' =>$thisPreview,
'body' => $thisBody,
), //columns
array(
'%d',
'%s',
'%s',
'%s',
'%s',
'%s',
)
);
}
a_faire($thisInput, $thisSub, $thisRecei, $thisPreview, $thisBody);
function a_faire($thisInput, $thisSub, $thisRecei, $thisPreview, $thisBody){
global $wpdb;
$wpdb->insert(
'a_faire', //table name
array(
'id_1' => '',
'from_mail' => $thisInput,
'subject' =>$thisSub,
'recei' => $thisRecei,
'preview' =>$thisPreview,
'body' => $thisBody,
), //columns
array(
'%d',
'%s',
'%s',
'%s',
'%s',
'%s',
)
);
}
&#13;
当我点击紧急按钮一切顺利时,INSERT就会生效并且运行良好。 当我点击a_do按钮时,它会在右表中很好地插入,但它也会在紧急表中进行INSERT。 我想我缺乏经验不是原因,我尝试了很多东西,但没有任何作用。如果有人可以告诉我解决问题的方法,我将不胜感激。
答案 0 :(得分:1)
我发现了问题的来源。错误来自我调用函数的方式......