0

最初の行の console.log は、値の大きな配列を返します。最後の Console.log(Data) にはサーバーからのプレーン テキスト応答が表示されますが、サーバーの $_POST 変数は空です。

JS:

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

console.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 変数が空である理由がわかりません。

4

2 に答える 2

0
$.post(url,{**NAMEME**: topost} ,function ( data ){
console.log(data);
});
于 2012-08-21T04:34:48.430 に答える
0

表示される配列として投稿データを渡そうとしています。文字列またはオブジェクトのいずれかである必要があります。

jQuery.post() のデータ プロパティの説明:

data リクエストとともにサーバーに送信されるマップまたは文字列。

http://api.jquery.com/jQuery.post/から

あなたがやろうとしていることに基づいて、ここで私の推測はオブジェクトです。これにより、次の問題が発生します。オブジェクトと PHP スクリプトの両方がキーと値の両方を想定していますが、値のみを渡しています。

データ オブジェクトは次のようになります。

topost = {
 somekey1: "DiscontentDisciple",
 somekey2: "illuminatedwax",    
 somekey3: "S2S2S2S2S2",
 // etc etc etc
};
于 2012-08-21T04:35:48.650 に答える