Jquery Post Empty即使发送变量有数据

Jquery Post Empty Even though Sent Variable has data

本文关键字:变量 数据 Post Empty Jquery      更新时间:2023-09-26

第一行的console.log返回一个大数组的值。结尾的Console.log(Data)显示来自服务器的纯文本响应,但服务器上的$_POST变量为空。

JS:

console.log(topost);
$.post(url,topost,function ( data ){
    console.log(data);
});

控制台.log(topost);

["DiscontentDisciple","illuminatedwax","S2S2S2S2S2","bechus","syncretic","davidreiss666","Skuld","soupyhands","AutoModerator","imluckytometyou","Lord_Arioc","IIdsandsII","Kylnas","alanpugh","langis_on","TheBigDickedBandit","long_wang_big_balls","arnoldlol","SBringer","ExoticCarMan","HaidiMontag","10FootPenis","SupriseRape","AManHasSpoken","ComedicCounterpart","Suddenly_Something","agenthex","GenerallySpecific","WelcomeToTarget","brainswho","Gooflactus","alcakd","Stingray88","TossTime","yolfer","biskits1","Evarg","phishroom","BuccoBruce","LookingForAlaska","getDense","lewisthemusician","tmotom","tha_ape","spankymuffin","Dashing_Pony","RuafaolGaiscioch","BeaverManiac","Careless_Con","Texas_","i_am_sad","The_helpful_idiot","Kon-chezz","bombdailer","frezik","Galifreyan2012","metalshadow","lightpollutionguy","b3mus3d","crazdave","merpes","naked_guy_says","GoodGuyAnusDestroyer","Bibliophobia","Internet_Lynch_Mob","photo","adkoe","ZeitTaicho","movie_man","iamkush","sired_tick","jyjjy","WhipIash","rred82","E_Diddyyy","CYBERPENISATTACK","MJYTR","TheBaconHasLanded","quarktheduck","heroic_trig","sleevieb","Burrow","myhousemateisabitch","promethephile","msm008","daskrip","jonnie123","Legendman3","Makes_Sad_Faces","anxiousalpaca","crankykong","IamDa5id","CocoSavege","iamsofuckedseriously","EvTheSmev","Briscotti","MarkieMarkl","CornishCucumber","BearsStillSuck","government_shill","Ihaveafatcat","gh5046","Sayum","henryponco","bolaxao","mrbriancomputer","PsychicNinja_","poopslooshed","REDDIT-","IVI4tt","spleendor","ngmcs8203","deadbeatbum","vegibowl","workingalot","Black_Apalachi","Incongruity7","rdeari1","ihahp","im_0n_toilet","Andynack","photokeith","Alpha17x","5NL70","AtticusFinch1962","clayvn","anonymau5","coplay","gnarbucketz","BukkRogerrs","teusz16","digital_evolution","theredcheck","empw","OrigamiRock","lumptoast","alphanovember","Nahtanos","som13","rstyknf","jmadden287","patchworkpavements","Computer-Blue","Miltage","bwaxxlo","aussiegolfer","coaltown","ThePickleMan","mpm96","Ilyanep","merreborn","Theemuts","wufoo2","thunderbar","blindado9","ntorotn","CatrickSwayze","HankSinatra","redditbots","Word_Inventor","catbeef","SoLongSidekick","Elefaze","Jinksywinksy","Mordy2011","thatusernameisal","Kanin","inthekeyofbflat","buckygrad","DeaD_bAU5","Toe_Fat","wsright987","Pachi2Sexy","woprdotmil","AmmoBradley","pokelord13","kroutonz","mattoftheD","WipeMyAssWith100s","ShuckBeam","dookyface","XLR8Sam","your_backpack"] 

我得到的回应:

{"postyn":"YES"} 

PHP:

foreach ($_POST as $key => $value){
    $data[$key] = $value;
}
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
    $data['postyn'] = 'YES';
}

我不明白为什么$_POST变量是空的?

$.post(url,{**NAMEME**: topost} ,function ( data ){
console.log(data);
});

您正试图将post数据作为一个数组进行传递。它必须是字符串或对象。

jQuery.post()的数据属性描述:

data随请求一起发送到服务器的映射或字符串。

来源http://api.jquery.com/jQuery.post/

根据你想做的事情,我猜这里是一个物体。这带来了下一个问题,对象和PHP脚本都需要键和值,但您只传递值。

您的数据对象应该看起来像:

topost = {
 somekey1: "DiscontentDisciple",
 somekey2: "illuminatedwax",    
 somekey3: "S2S2S2S2S2",
 // etc etc etc
};