阿贾克斯到PHP不会工作 [英] Ajax to php wont work

查看:149
本文介绍了阿贾克斯到PHP不会工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一个事件侦听器附加到一个按钮,点击时会作出AJAX调用。

I am trying to attach an event listener to a button that will make an ajax call when clicked.

我已经设置在我们称之为test.php的一个文件中的一些PHP的一边。 我已经使用了现场jQuery函数来攻击一个点击事件的按钮。 阿贾克斯功能将通过页的test.php的上输入元素的值。 然后test.php的文件将使用该值来确定它要使用的文件的URL。 该test.php的文件dedupes基于匹配电子邮件csv文件。 CSV文件是通过上传输入元素上传。

I have set aside some php in a file we shall call test.php. I have used the live jquery function to attack a click event to the button. The ajax function will pass a value of an input element on the page to the test.php. The test.php file will then use that value to determine the url of the file it is to use. The test.php file dedupes the csv file based on matching emails. The csv file is uploaded via an upload input element.

下面是我的code,不工作目前。拉琴表明,一个请求被发送到服务器,但上的响应是没有着落

Here is my code, that is not working currently. Fiddler shows that a request is being sent out to the server but a response is not forthcoming.

HTML

<input type="button" id="csv_dedupe" value="dedupe-file">

jQuery的

$_CFG_PROCESSORFILE = "http://localhost/Gene/IMEXporter/include/IMEXporter_processor.php";

$("#csv_dedupe").live("click", function(e) {
    file_name = 'C:\\server\\xampp\\Gene\\IMEXporter\\include\\files\\' + $("#IMEXp_import_var-uploadFile-file").val();
    $.post($_CFG_PROCESSORFILE, {"task": "csv_dupe", "file_name": file_name}, function(data) {
        alert("success");
    }, "json")
});

PHP

if ($task == "csv_dupe") {
$input_filename = $_REQUEST["file_name"];
$output_filename = $_REQUEST["file_name"];

$input_file = fopen($input_filename, 'r');
$output_file = fopen($output_filename, 'w');
$email_addresses = array();
// Read the header
$headers = fgetcsv($input_file, 0);
fputcsv($output_file, $headers);
// Flip it so it becomes name => ID
$headers = array_flip($headers);

// Read every row
while (($row = fgetcsv($input_file, 0)) !== FALSE)
{
    $email = $row[$headers['email']];
    // Do we already have this email address?
    if (isset($email_addresses[$email]))
        continue;

    // Mark this email as being found
    $email_addresses[$email] = true;
    // Write it to the output
    fputcsv($output_file, $row);
}

}

我似乎无法弄清楚为什么它不工作,我在做什么错。任何想法将AP preciated。

I cant seem to figure out why its not working and what I am doing wrong. Any ideas would appreciated.

修改 * 固定的,但新的错误显示的*

我收到了一些错误时,该请求返回。

I received some errors when the request returned.

警告:fputcsv()预计参数2是数组,布尔在C中给出:\服务器\ XAMPP \ htdocs中\基因\ IMEXporter \包括\ IMEXporter_processor.php在线45

Warning: fputcsv() expects parameter 2 to be array, boolean given in C:\server\xampp\htdocs\Gene\IMEXporter\include\IMEXporter_processor.php on line 45

警告:array_flip()预计参数1是数组,布尔在C中给出:\服务器\ XAMPP \ htdocs中\基因\ IMEXporter \包括\ IMEXporter_processor.php在线47 成功

Warning: array_flip() expects parameter 1 to be array, boolean given in C:\server\xampp\htdocs\Gene\IMEXporter\include\IMEXporter_processor.php on line 47 "success"

推荐答案

发现有人有类似问题的此处

Found someone with a similar problem here.

打开文件时添加行

ini_set('auto_detect_line_endings',TRUE);

fgetcsv(),当它到达文件的结束返回的假的布尔值。从PHP-手册:

fgetcsv() is returning a boolean value of "false" when it reaches the end of the file. From php-manual:

fgetcsv() returns NULL if an invalid handle is supplied or FALSE on other errors, including end of file.

引用

  • http://php.net/manual/en/function.fgetcsv.php
  • php fgetcsv returning all lines

这篇关于阿贾克斯到PHP不会工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆