저는 다른 아약스 메소드를 사용하여 여러 가지 방법을 시도해 보았지만 제대로 작동하지 않습니다. 나는 아약스와 json을 처음 사용하므로 데이터가 형태가 아닌 다른 아약스 프로세스가 구조화되어 작동한다고 생각할 수있다. 입력은 클릭 할 때 집어 들고 콘솔에 나타나지만 데이터가 보인다 : PHP에 변수를 보내지 않는다. 왜냐하면 실패 할 경우 경고 상자에 데이터가 반환되지 않기 때문이다. SQL 쿼리 등 PHP에서 잘 실행 Myadmin 그래서 마지막에 메신저 및 분실 하하! 누군가 나를 도울 수 있기를 바란다 !! 덕분에 고급!Ajax가 JSON 객체의 PHP에 데이터를 게시하지 않습니다.
HTML
<?php
$page = "Blog | Fakebook";
include "../inc/connect.php";
include "../inc/login-check.php";
include "../inc/header.php";
include "../inc/menus.php";
?>
<div id="content-wrap" class="create-a-blog">
<?php
include "../inc/modals.php";
echo "<input type='hidden' name='author' value='" . $_SESSION['userID'] . "' />"
?>
<div id="hero">
<a id="ajax-blog-bg" class="btn btn-hollow-wht add-img">Add Image</a>
<a id="ajax-publish-blog" class="btn btn-hollow-wht pub-blg">Publish Blog</a>
<section class='create-blog-title'>
<textarea id="edit-blog-title" name="blog-title" class="title-input" >Enter Blog Title</textarea>
<!-- <p>Date and your name will be shown here</p>-->
</section>
</div>
<div id="create-blog-content">
<div class="container rel">
<article class="article">
<textarea id="edit-blog-content" rows='4' name='blog-content' cols='50' >Go ahead and get your blog started</textarea>
</article>
</div>
</div>
</div>
AJAX
$("#ajax-publish-blog").click(function (e){
event.preventDefault();
var blogTitle = $('#edit-blog-title').val();
var content = $('#edit-blog-content').val();
var image = $('.create-a-blog #hero').css('background-image');
var cleanup = /\"|\'|\)/g;
var bg = image.split('/').pop().replace(cleanup, '');
var authorID = $('input[name=author]').val();
console.log("Blog Title = " + blogTitle + " // Blog Content = " + content + " // bg image = " + bg + " // authorID =" + authorID);
$.ajax({
url: "../process/post-blog-process2.php",
type: "POST",
data: { blogTitle: blogTitle, content: content, image: bg, authorID: authorID },
dataType: 'json',
success: function(data){
alert("ohyer" + " " + data.title + " " + data.authorID + " " + data.content + " " + data.image)
},
error: function(data) {
alert("ohno" + " " + data.title + " " + data.authorID + " " + data.content + " " + data.image)
}
});
});
PHP
<?php
session_start(); //start a session
include "../inc/connect.php"; //include the database connection
//prevent SQL injection and get data from inputs
$blogTitle = mysqli_real_escape_string($con, $_POST['blogTitle']);
$image = mysqli_real_escape_string($con, $_POST['image']);
$content = mysqli_real_escape_string($con, $_POST['content']);
$authorID = mysqli_real_escape_string($con, $_POST['author']);
$sql="INSERT INTO blog (blogTitle, image, content, date, authorID) VALUES ('$blogTitle', '$image', '$content', NOW(), '$authorID')";
$result = mysqli_query($con, $sql) or die(mysqli_error($con)); //run the query
if (!$result) {
$data['success'] = false;
$data['title'] = $blogTitle;
$data['authorID'] = $authorID;
$data['content'] = $content;
$data['image'] = $image;
} else {
$data['success'] = true;
$data['redirect'] = '../pages/blog.php';
}
echo json_encode($data);
?>
처음에는 코드를 정리하십시오. 코드 전체가 전달되는 경우는 거의 도움이되지 않습니다. 우리가 볼 필요가있는 코드를 게시하십시오. – Utkanos
@Whathaveyoutried URL이 맞습니다. –
@Utkanos 문제가 어디에 있는지 잘 모르겠습니다. 그리고 대부분의 경우에 모든 코드 원인을 포함 시켰습니다. 하나의 언어 만 포함하면 모든 사람들이 더 많은 코드를 요구합니다. –