我正试图通过ajax发布数据,这是我的信息:
var jsondata =
{"address" : [
{ "id": addid, "streetaddress": streetaddress, "city": city, "state": state, "zipcode": zipcode, "latitude": latitude},
]
};
var jsontosend = JSON.stringify(jsondata, null, 2);
Run Code Online (Sandbox Code Playgroud)
ajax功能:
$.ajax({
type: "POST",
url: "process.php",
contentType: "application/json; charset=utf-8",
dataType: "JSON",
data: jsontosend,
success: function(msg){
alert(msg);
}
});
return false;
alert('Data sent');
Run Code Online (Sandbox Code Playgroud)
}
在php结束时,当我print_r($ _ POST)它只是说
array(0) {
}
Run Code Online (Sandbox Code Playgroud)
我正在警告(jsontosend)并且它完美地展示了我的一切,以及使用post mothod的firebug,它以完美的清洁方式显示所有的参数.
它传递任何数据的唯一方法是使用GET方法.
任何意见是极大的赞赏!
编辑:从firebug添加POST数据.这是警报功能提醒的:
{"address":[{"id":1473294,"streetaddress":"3784 Howard Ave","city":"Washington DC","state":"DC","zipcode":20895,"latitude":39.027820587}]}
Run Code Online (Sandbox Code Playgroud)
这是firebug在使用POST方法时传递的内容:
myData=%7B%0A++++%22address%22%3A+%5B%0A++++++++%7B%0A++++++++++++%22id%22%3A+76076%2C%0A++++++++++++%22streetaddress%22%3A+%223784+Howard+Ave%22%2C%0A++++++++++++%22city%22%3A+%22Washington+DC%22%2C%0A++++++++++++%22state%22%3A+%22DC%22%2C%0A++++++++++++%22zipcode%22%3A+20895%2C%0A++++++++++++%22latitude%22%3A+39.027820587%0A++++++++%7D%0A++++%5D%0A%7D
Run Code Online (Sandbox Code Playgroud)
这是$ _POST的var_dump的响应:
array(0) {
Run Code Online (Sandbox Code Playgroud)
}
这是$ _POST ['myData']的var_dump
NULL
Run Code Online (Sandbox Code Playgroud) 在插入数据库之前,我使用以下代码来检查重复项.对我来说,重复的只考虑重复时name,description,price,city,和enddate比赛.
foreach($states_to_add as $item) {
$dupesql = "SELECT
COUNT(*)
FROM
table
WHERE
(
name = '$name'
AND description = '$description'
AND manufacturer = '$manufacturer'
AND city ='$city'
AND price = '$price'
AND enddate = '$end_date'
)";
$duperaw = mysql_query($dupesql);
if($duperaw > 0) {
echo nl2br("$name already exists in $city \n");
}
else {
$sql = "INSERT INTO table (..... (here go the values to be inserted)
....
Run Code Online (Sandbox Code Playgroud)
在运行此检查之前定义每个值,我的结果总是在项目已存在时返回.我倾倒了"dupesql"并将命令复制/粘贴到phpmyadmin中,后者返回计数0.
我的脚本使用mysql,tiny_tds,fileutils和net/ftp.在ruby 1.9.3上运行.当我从文件夹内部运行它时,它工作得很好.
但是,当我将它添加到cron选项卡时,tiny_tds经常失败.我不知道是否有任何其他宝石失败,因为我无法通过此错误:
require':没有要加载的文件 - tiny_tds(LoadError)
我尝试从crontab使用的同一个shell执行它,我得到了那个错误.
整个脚本只有一个文件.
我是红宝石的新手,所以我的知识在以正确的方式设置环境方面是有限的.
在我的文件的头部
#!/usr/bin/ruby
require "mysql"
require "fileutils";
require "tiny_tds"
require "net/ftp"
Run Code Online (Sandbox Code Playgroud)
简而言之,我从mysql获取了一个Jobs列表,将其与MsSQL进行比较,将FTP文件与之相比较,并在作业完成时再次更新mysql.
我需要从cron运行它.
经过一段时间的研究,我试图将宝石设置为全局,但是,我认为这可能没有用.
在此先感谢您的帮助!
我正在尝试使用htaccess减少我的URL,我的index.php充当以下代码的密钥:
RewriteEngine on
RewriteRule ^([^/]+)$ index.php?city=$1 [NC]
Run Code Online (Sandbox Code Playgroud)
要在我的会员区使用此功能,我是否只需添加以下内容即可使用mysite.com/members/index.php?city=$1
RewriteRule ^members/([^/]+)$ index.php?city=$1 [NC]
Run Code Online (Sandbox Code Playgroud)
如果一个城市有多个单词,即:纽约市,最好的办法是什么?在.htaccess中定义它(不确定是否可能)改变纽约市 - >纽约市或实际上任何空间到破折号.或者,在php中使用函数来替换'' - >' - '用于使用$ _GET的数据库查询?
我有以下功能
function blah($string) {
$match = array('red', 'green', 'blue');
$replace = array('1', '1,', '0');
return str_replace($match, $replace $string);
}
Run Code Online (Sandbox Code Playgroud)
我要做的是,如果输入不在匹配数组中,则返回0.
由于这只在后端使用一次/天,性能不是最大的问题,但由于我还在学习PHP,我想了解这样做的正确方法.
任何帮助真的很感激!提前致谢!
我正在尝试使用jquery数据选择器向元素添加/删除类.
$("#side_categories .testbox").click(function () {
var category = $(this).data('category'); //get the category from the clicked button
if ($('#side_categories .testbox').hasClass('activated')) {
//otherInput is the hidden text input
$('#listings .deals:data("category"="+category+")').removeClass('activated');
} else {
$('#listings .deals:data("category"="+category+")').addClass('activated');
}
});
Run Code Online (Sandbox Code Playgroud)
在我的测试框中,我在每个触发器上设置了数据类别以将其传递过来.进入数据类别的类别通过php填写.
似乎无法让这个工作,已经看到错误像:
regular expression too complex
[Break On This Error] while (m = matcher.exec(expr)) {
Run Code Online (Sandbox Code Playgroud)
或者当我使用james padolsey编写的旧函数时,我得到以下内容:
uncaught exception: Syntax error, unrecognized expression: data
Run Code Online (Sandbox Code Playgroud)
我只是希望能够根据复选框选择从LI中添加/删除类.
提前谢谢了!
php ×4
.htaccess ×1
ajax ×1
arrays ×1
cron ×1
duplicates ×1
if-statement ×1
jquery ×1
json ×1
mysql ×1
ruby ×1
rvm ×1
str-replace ×1
tiny-tds ×1