首页 \ 问答 \ jQuery Ajax不发送Post数据到PHP文件(jQuery Ajax not sending Post data to PHP file)

jQuery Ajax不发送Post数据到PHP文件(jQuery Ajax not sending Post data to PHP file)

我试图使用AJAX将我的JavaScript变量发送到PHP文件,但它不起作用。 我浏览了所有类似的问题(有一堆),但还没有找到解决方案。

这是我的第一个PHP文件(一个带有表单,将数据发送到JavaScript):

<option value="imageOne" data-cuteform-image='assets/SketchThumbnails/imageOne.png></option>
<input id="inputURLID" type="text" name="inputURL">

<button type="submit" onclick="handleInputs(document.getElementById('sketch').value, document.getElementById('inputURLID').value); return false;">Submit</button>

JavaScript(AJAX调用的地方)

var content = {
    'sketch': pickedSketch,
    'songUrl': enteredURL
};
$.ajax({
    type: "POST",
    url: "loadSketch.php",
    data: content,
    success: function (data, text) {
        // alert("success");
        // console.log(data);
        // console.log(text);

        window.location.href = "loadSketch.php";

    },
    error: function (request, status, error) {
        alert(request.responseText);
    }
});

PHP(loadSketch.php):

if(isset($_POST['songUrl']))
{
    $temp = $_POST['songUrl'];
    echo $temp;
    echo "received AJAX data";
} else {
    echo "nothing in post variable";
}

当我被重定向到loadSketch.php(来自成功的ajax调用)时,“post变量中的任何内容”都被回显出来。 任何想法我做错了什么?

任何有识之士都非常感谢! :)


I'm trying to send variables from my JavaScript to a PHP file using AJAX but it's not working. I've looked through all the similar asked questions (there are a bunch) but have yet to find a solution.

This is my first php file (one with the form, sends data to JavaScript):

<option value="imageOne" data-cuteform-image='assets/SketchThumbnails/imageOne.png></option>
<input id="inputURLID" type="text" name="inputURL">

<button type="submit" onclick="handleInputs(document.getElementById('sketch').value, document.getElementById('inputURLID').value); return false;">Submit</button>

JavaScript (where AJAX call is):

var content = {
    'sketch': pickedSketch,
    'songUrl': enteredURL
};
$.ajax({
    type: "POST",
    url: "loadSketch.php",
    data: content,
    success: function (data, text) {
        // alert("success");
        // console.log(data);
        // console.log(text);

        window.location.href = "loadSketch.php";

    },
    error: function (request, status, error) {
        alert(request.responseText);
    }
});

PHP (loadSketch.php):

if(isset($_POST['songUrl']))
{
    $temp = $_POST['songUrl'];
    echo $temp;
    echo "received AJAX data";
} else {
    echo "nothing in post variable";
}

When I get redirected to loadSketch.php (from the successful ajax call), "nothing in post variable" gets echoed out. Any ideas what I'm doing wrong?

Any insight is much appreciated! :)


原文:https://stackoverflow.com/questions/40699251
更新时间:2024-02-01 19:02

最满意答案

数组不能为零。

ISO 9899:2011 6.7.6.2:

如果表达式是一个常量表达式,它的值应大于零。

上述文本对于纯数组(第1段)是真实的。 对于VLA(可变长度数组),如果表达式的值小于或等于零,则该行为是未定义的(第5段)。 这是C标准的规范性文本。 编译器不允许以不同的方式实现它。

gcc -std=c99 -pedantic给出非VLA情况的警告。


An array cannot have zero size.

ISO 9899:2011 6.7.6.2:

If the expression is a constant expression, it shall have a value greater than zero.

The above text is true both for a plain array (paragraph 1). For a VLA (variable length array), the behavior is undefined if the expression's value is less than or equal to zero (paragraph 5). This is normative text in the C standard. A compiler is not allowed to implement it differently.

gcc -std=c99 -pedantic gives a warning for the non-VLA case.

相关问答

更多
  • 数组不能为零。 ISO 9899:2011 6.7.6.2: 如果表达式是一个常量表达式,它的值应大于零。 上述文本对于纯数组(第1段)是真实的。 对于VLA(可变长度数组),如果表达式的值小于或等于零,则该行为是未定义的(第5段)。 这是C标准的规范性文本。 编译器不允许以不同的方式实现它。 gcc -std=c99 -pedantic给出非VLA情况的警告。 An array cannot have zero size. ISO 9899:2011 6.7.6.2: If the expression ...
  • 全局变量应该在.h文件中声明,并且应该声明为extern ,然后它们应该在.c文件中定义。 查看声明和定义全局变量和函数的最佳方式是什么? 从comp.lang.c常见问题。 对于阵列,可能需要特别注意。 请参阅comp.lang.c FAQ中的Q1.24 。 Globals should be declared in a .h file and should be declared as extern, and then they should be defined in a .c file. See W ...
  • 编译器使用非标准扩展。 您的代码无效,标准C ++。 可变长度数组不是C ++的一个特性。 请注意,大小必须是编译时常量,而不仅仅是常量(即const )。 The compiler is using a non-standard extension. Your code isn't valid, standard C++. Variable length arrays aren't a feature of C++. Note that the size has to be a compile-time ...
  • 这样的事情怎么样? 它适用于简单的可复制类型: template class packed_array { public: packed_array(INT size) { buf_ = new char[sizeof(INT) + size * sizeof(T)]; memcpy(buf_, &size, sizeof(INT)); } ~packed_array() { dele ...
  • 相当于是 def CSYNC_VERSION_INT(a, b, c): return a << 16 | b << 8 | c 它左移16位, b左移8和c完好; 那么所有这些数字都一起按比例排列。 因此a, b, c它将a, b, c打包为一个整数的三(4)个字节,以便最低字节是c的值,其次是b ,最高字节是a值。 CSYNC_VERSION_INT(3, 2, 8)等于十六进制中的0x30208,或十进制中的197128。 The equivalent would be def CSYNC_ ...
  • 如果使用define语句,代码中的所有KEY_ESC_实例将被字面替换为(char []){27,0,0,0,0,0,0},这将在您的代码中的该点处变为临时变量。 If you use a define statement, all instances of KEY_ESC_ in your code will be literally replaced by (char[]) {27, 0, 0, 0, 0, 0, 0}, which will at that point in your code bec ...
  • 如果数组的某个维度是可变的,那么大小必须是可变的,那么它必须是动态调整大小的 - 或者以这样的方式调整大小,使得数组的静态大小大于变量可能的最大值。 If one of the dimensions of the array is variable, then the size must be variable, then it must be dynamically sized - or sized in such a way that the the array is statically sized ...
  • 是的,可以这样做。 您根本不需要命名结构,这使得宏更简单: #define CHAR_ARRAY(MAX_LENGTH) struct {char data[MAX_LENGTH]; int length;} (在您的示例中使用。) 但是,我仍然不完全清楚这个宏的目的,因为这实际上重新实现了现有的功能。 至少你应该使用模板而不是宏来为你生成类型: template struct char_array { char data[N]; std::size_t length; } ...

相关文章

更多

最新问答

更多
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)
  • 是否可以嵌套hazelcast IMaps?(Is it possible to nest hazelcast IMaps? And whick side effects can I expect? Is it a good Idea anyway?)
  • UIViewAnimationOptionRepeat在两个动画之间暂停(UIViewAnimationOptionRepeat pausing in between two animations)
  • 在x-kendo-template中使用Razor查询(Using Razor query within x-kendo-template)
  • 在BeautifulSoup中替换文本而不转义(Replace text without escaping in BeautifulSoup)
  • 如何在存根或模拟不存在的方法时配置Rspec以引发错误?(How can I configure Rspec to raise error when stubbing or mocking non-existing methods?)
  • asp用javascript(asp with javascript)
  • “%()s”在sql查询中的含义是什么?(What does “%()s” means in sql query?)
  • 如何为其编辑的内容提供自定义UITableViewCell上下文?(How to give a custom UITableViewCell context of what it is editing?)
  • c ++十进制到二进制,然后使用操作,然后回到十进制(c++ Decimal to binary, then use operation, then back to decimal)
  • 以编程方式创建视频?(Create videos programmatically?)
  • 无法在BeautifulSoup中正确解析数据(Unable to parse data correctly in BeautifulSoup)
  • webform和mvc的区别 知乎
  • 如何使用wadl2java生成REST服务模板,其中POST / PUT方法具有参数?(How do you generate REST service template with wadl2java where POST/PUT methods have parameters?)
  • 我无法理解我的travis构建有什么问题(I am having trouble understanding what is wrong with my travis build)
  • iOS9 Scope Bar出现在Search Bar后面或旁边(iOS9 Scope Bar appears either behind or beside Search Bar)
  • 为什么开机慢上面还显示;Inetrnet,Explorer
  • 有关调用远程WCF服务的超时问题(Timeout Question about Invoking a Remote WCF Service)