Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Ajax发布问题_Javascript_Php_Jquery_Ajax - Fatal编程技术网

Javascript Ajax发布问题

Javascript Ajax发布问题,javascript,php,jquery,ajax,Javascript,Php,Jquery,Ajax,我正在开发一个功能,其中包括发布到ajax。相关的代码位应该选择某个类,循环遍历它的元素,将所需的元素放入数组中,然后发布该数组。它可以很好地获取背景图像链接。然而,同样的概念在应用于html文本区域中编写的文本时似乎失败了。尽管我使用.val方法从textarea获取文本并将其推送到相关数组中,然后发布,但没有文本上传到数据库。这里是javascript $('#createButton').click(function() { var getImages = [];

我正在开发一个功能,其中包括发布到ajax。相关的代码位应该选择某个类,循环遍历它的元素,将所需的元素放入数组中,然后发布该数组。它可以很好地获取背景图像链接。然而,同样的概念在应用于html文本区域中编写的文本时似乎失败了。尽管我使用.val方法从textarea获取文本并将其推送到相关数组中,然后发布,但没有文本上传到数据库。这里是javascript

$('#createButton').click(function() {
        var getImages = []; 
        var getText = []; 
        var count = $('.count').length; 
        var tcount = $('.tcount').length; 

        if ( count >= 1 ) {
            $('.count').each(function () {
                if ($(this).css('background-image')) {
                    var src = $(this).css('background-image');
                    var parseSrc = src.replace(/^.*(?=images)|\W+$/g, ''); //parse out the actual link from url( link )
                    getImages.push(parseSrc); 
                }//end nested if 
            });//end each function 
        }//end count if
        if ( tcount >= 1 ) {

            $('.tcount').each(function () {
                  if ($(this).val()) {
                    var textVal = $(this).val(); 
                    getText.push(textVal);  
               }//end if
            });//end each
        }//end tcount if
        $.post('fileHandler.php', {image: getImages, text: getText});//end post
    });//end createButton click
还有PHP

include('classes/fileclass.php'); 

$f = new Files (); 
$storyID = $f->idHandler(); 

if ($_POST['image']) {
foreach($_POST['image'] as $imageSrc) {
    $f->insertStoryImages($storyID, $imageSrc); 
}//end foreach  
if ($_POST['text']) {
    foreach($_POST['text'] as $textBox) {
        $f->insertStoryText($storyID, $textBox);  
    }//end foreach
}//end text if 
}//end image if 
以及从OOP脚本实际执行服务器调用的位(仅对于文本调用,图像工作正常):


注意:
.tcount
类会选择一个html文本区域对象

问题在于“.tcount”不是表示textarea,而是表示div。因此,当我使用.val()时,它自然会返回一个空字符串。可怕的虫子

首先,您必须确定错误在哪里。我建议在PHP部分的一开始就在日志或控制台中编写$_POST['text']的内容。通过这种方式,你可以在PHP或javascript部分集中注意力。如果你观看浏览器的javascript控制台(至少是Chrome或Firefox),你应该会看到AJAX调用被执行。。。数据的结构是否符合您的预期?如果是这样,问题就出在服务器端。如果不是的话,它的客户端。谢谢你回来发布实际发生的事情!
public function insertStoryText ($storyID, $textBox) {
    $db = new pdo("mysql:host=localhost;dbname=storyboard;charset=utf8", "someuser", "somepass");
    $stmt = $db->prepare("INSERT INTO sbData(storyID, textBox) VALUES (:storyID, :textBox)");
    $stmt->execute(array(':storyID' => $storyID, ':textbox' => $textBox));
}//end insertShoot