嗨,我有这个简单的代码:
var datastring="123";
$.ajax({
url: 'actualizarimagen.php',
type: 'post',
dataType: 'text',
data: datastring,
cache: false,
success: function(response){
$('.msg1').html(response);
},
error: function(response){
$('.msg1').html(response);
}
});
在 actualizarimagen.php 中:
$desc_larga = print('<pre>') & print_R($_POST) & print('</pre>');
$insertSQL = sprintf("INSERT INTO prueba (texto) VALUES ($desc_larga)");
我收到成功消息,但在数据库中始终保存 1。我尝试更改所有内容,数据类型、成功、错误、完整功能,但它不起作用。我正在搜索,但任何答案都帮不了我。
谢谢。
编辑:添加响应
最佳答案
您的 datastring
应包含编码为 application/x-www-form-urlencoded
的数据
例如:var datastring="foo=123";
最好不要将字符串传递给 jQuery。将一个对象传递给它,让它为您处理编码。
例如:data: { "foo": "123"}
关于php - ajax成功但不发送发布数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10639757/