我有一个foo发出Ajax请求的函数.我怎样才能从中回复foo?
我尝试从success回调中返回值,并将响应分配给函数内部的局部变量并返回该变量,但这些方法都没有实际返回响应.
function foo() {
var result;
$.ajax({
url: '...',
success: function(response) {
result = response;
// return response; // <- I tried that one as well
}
});
return result;
}
var result = foo(); // It always ends up being `undefined`.
Run Code Online (Sandbox Code Playgroud) 我正在尝试学习编写查询的最佳方法.我也理解保持一致的重要性.到现在为止,我已经随机使用了单引号,双引号和后退,没有任何实际想法.
例:
$query = 'INSERT INTO table (id, col1, col2) VALUES (NULL, val1, val2)';
Run Code Online (Sandbox Code Playgroud)
此外,在上面的例子中,考虑table可能是变量.
这是什么标准?你是做什么?
我一直在这里阅读类似问题的答案大约20分钟,但看起来这个问题没有明确的答案.
我正在尝试在内容表中插入值.如果我在VALUES中没有PHP变量,它可以正常工作.当我将变量$type放在VALUES中时,这不起作用.我究竟做错了什么?
$type = 'testing';
mysql_query("INSERT INTO contents (type, reporter, description)
VALUES($type, 'john', 'whatever')");
Run Code Online (Sandbox Code Playgroud) mysql ×2
sql ×2
ajax ×1
asynchronous ×1
javascript ×1
jquery ×1
php ×1
quotes ×1
string ×1
variables ×1