我有一个onload正在向表单添加字段的页面,但是这个调用似乎永远不会进入getJSON中的.each语句。我可以在Chrome的网络选项卡上看到使用GET获取的网址,但它不会向我的表单添加任何输入。
$.each( brand, function( key, value ) {
if(domain == value) $("#brand").show();
$.getJSON( 'http://forms.anniesatticmysteries-news.com/ats/url.aspx?cr=422&wu=1', function( data ) {
$.each( data, function( key, val ) {
$("#brandForm").append('<input type="hidden" name="s_email_sp'+ [value][0] +'_status_id" value="'+ [value][2] +'" /> ');
});
});
});
这是我的json对象的一部分。
{
"anniescatalog-news.com":["1","email_sp1_status_id","{(email_sp1_status_id)}"],
"anniesmysteries-news.com":["2","email_sp2_status_id","{(email_sp2_status_id)}"],
"anniesnewsletters-news.com":["3","email_sp3_status_id","{(email_sp3_status_id)}"],
"annies-publishing-news.com":["4","email_sp4_status_id","{(email_sp4_status_id)}"]
}
域名与我请求的域名相同,因此它不应该是跨站点问题。以下是网址:http://forms.anniesatticmysteries-news.com/ats/show.aspx?cr=422&fm=43&dm=AnniesAtticMysteries-news.com
答案 0 :(得分:1)
我很确定您的Json格式不正确,无法满足您的需求。
如果你采取:
var obj1 = {
"anniescatalog-news.com":["1","email_sp1_status_id","{(email_sp1_status_id)}"],
"anniesmysteries-news.com":["2","email_sp2_status_id","{(email_sp2_status_id)}"],
"anniesnewsletters-news.com":["3","email_sp3_status_id","{(email_sp3_status_id)}"],
"annies-publishing-news.com":["4","email_sp4_status_id","{(email_sp4_status_id)}"]
};
如果你在检查员中看到这个,你可以看到网址是属性名称而不是值:
因此您无法访问anniescatalog-news.com
作为值。该属性名为 anniescatalog-news.com: obj1.anniescatalog-news.com == "1","email_sp1_status_id","{(email_sp1_status_id)}"
Fiddle here
如果您可以将Json更改为:
[
{name:"anniescatalog-news.com", value:["1","email_sp1_status_id","{(email_sp1_status_id)}"]},
{name:"anniesmysteries-news.com", value:["2","email_sp2_status_id","{(email_sp2_status_id)}"]},
{name:"anniesnewsletters-news.com", value:["3","email_sp3_status_id","{(email_sp3_status_id)}"]},
{name:"annies-publishing-news.com", value:["4","email_sp4_status_id","{(email_sp4_status_id)}"]}
]
或类似的。现在您有一个包含[]
和{}
对的数组(Json表示法:name
)对象(Json表示法:value
)。因此,您可以访问这些:
var obj1 = [
{name:"anniescatalog-news.com", value:["1","email_sp1_status_id","{(email_sp1_status_id)}"]},
{name:"anniesmysteries-news.com", value:["2","email_sp2_status_id","{(email_sp2_status_id)}"]},
{name:"anniesnewsletters-news.com", value:["3","email_sp3_status_id","{(email_sp3_status_id)}"]},
{name:"annies-publishing-news.com", value:["4","email_sp4_status_id","{(email_sp4_status_id)}"]}
];
$.each(obj1, function(index, obj2) {
alert(obj2.name);
});
您也可以访问值数组:
obj2.value[1]
BTW标准的Json序列化程序倾向于对这种东西进行哈希处理。我推荐Json.Net以获得更好的效果。
由于某种原因,您的回复格式错误:
[
{name:"anniescatalog-news.com", value:["1","email_sp1_status_id",""]},
{name:"anniesmysteries-news.com", value:["2","email_sp2_status_id",""]},
{name:"anniesnewsletters-news.com", value:["3","email_sp3_status_id",""]},
{name:"annies-publishing-news.com", value:["4","email_sp4_status_id",""]},
{name:"anniesquiltedmysteries-news.com", value:["5","email_sp5_status_id",""]},
{name:"annieswsl-news.com", value:["6","email_sp6_status_id",""]},
{name:"cardmakerkitclub-news.com", value:["email_sp7_status_id",""]},
{name:"cardmakermagazine-news.com", value:["email_sp8_status_id",""]},
{name:"countrysampler-news.com", value:["email_sp9_status_id",""]},
{name:"creativegirlsclub-news.com", value:["email_sp10_status_id",""]},
{name:"creativeknittingmagazine-news.com", value:["email_sp11_status_id",""]},
{name:"creativequiltersfabricclub-news.com", value:["email_sp12_status_id",""]},
{name:"creativewomanmysteries-news.com", value:["email_sp13_status_id",""]},
{name:"crochetmagazine-news.com", value:["email_sp14_status_id",""]},
{name:"crochet-world-news.com", value:["email_sp15_status_id",""]},
{name:"e-patternscentral-news.com", value:["email_sp16_status_id",""]},
{name:"freebeadguide-news.com", value:["email_sp17_status_id",""]},
{name:"free-cardmaking-news.com", value:["email_sp18_status_id",""]},
{name:"free-crochet-news.com", value:["email_sp19_status_id",""]},
{name:"free-knitpatterns-news.com", value:["email_sp20_status_id",""]},
{name:"freepatterns-news.com", value:["email_sp21_status_id",""]},
{name:"free-quilting-news.com", value:["email_sp22_status_id",""]},
{name:"freequiltingguide-news.com", value:["email_sp23_status_id",""]},
{name:"free-sewing-news.com", value:["email_sp24_status_id",""]},
{name:"freesewingguide-news.com", value:["email_sp25_status_id",""]},
{name:"goodolddaysmagazine-news.com", value:["email_sp26_status_id",""]},
{name:"goodolddaysstore-news.com", value:["email_sp27_status_id",""]},
{name:"hookandneedleclub-news.com", value:["email_sp28_status_id",""]},
{name:"just-crossstitch-news.com", value:["email_sp29_status_id",""]},
{name:"knitandcrochetnow-news.com", value:["email_sp30_status_id",""]},
{name:"learntoknitsocks-news.com", value:["email_sp31_status_id",""]},
{name:"liveitagain-news.com", value:["email_sp32_status_id",""]},
{name:"quiltersworld-news.com", value:["email_sp33_status_id",""]},
{name:"sanqmagazine-news.com", value:["email_sp34_status_id",""]},
{name:"simplybeadskitclub-news.com", value:["email_sp35_status_id",""]},
{name:"youngwoodworkers-news.com", value:["email_sp36_status_id",""]},
{name:"anniescatalog-orders.com", value:["email_sp37_status_id",""]},
{name:"annieswsl-orders.com", value:["email_sp38_status_id",""]},
{name:"e-patternscentral-orders.com", value:["email_sp39_status_id",""]},
{name:"goodolddaysstore-orders.com", value:["email_sp40_status_id",""]},
{name:"orders.annies-publishing-news.com", value:["email_sp41_status_id",""]},
{name:"orders.anniesquiltedmysteries-news.com", value:["email_sp42_status_id",""]},
{name:"orders.cardmakerkitclub-news.com", value:["email_sp43_status_id",""]},
{name:"orders.cardmakermagazine-news.com", value:["email_sp44_status_id",""]},
{name:"orders.countrysampler-news.com", value:["email_sp45_status_id",""]},
{name:"orders.creativegirlsclub-news.com", value:["email_sp46_status_id",""]},
{name:"orders.creativeknittingmagazine-news.com", value:["email_sp47_status_id",""]},
{name:"orders.creativequiltersfabricclub-news.com", value:["email_sp48_status_id",""]},
{name:"orders.creativewomanmysteries-news.com", value:["email_sp49_status_id",""]},
{name:"orders.crochetmagazine-news.com", value:["email_sp50_status_id",""]},
{name:"orders.crochet-world-news.com", value:["email_sp51_status_id",""]},
{name:"orders.goodolddaysmagazine-news.com", value:["email_sp52_status_id",""]},
{name:"orders.hookandneedleclub-news.com", value:["email_sp53_status_id",""]},
{name:"orders.just-crossstitch-news.com", value:["email_sp54_status_id",""]},
{name:"orders.liveitagain-news.com", value:["email_sp55_status_id",""]},
{name:"orders.quiltersworld-news.com", value:["email_sp56_status_id",""]},
{name:"orders.sanqmagazine-news.com", value:["email_sp57_status_id",""]},
{name:"orders.simplybeadskitclub-news.com", value:["email_sp58_status_id",""]},
{name:"orders.youngwoodworkers-news.com", value:["email_sp59_status_id",""]},
{name:"email.anniesnewsletters-news.com", value:["email_sp60_status_id",""]},
{name:"email.anniescatalog-news.com", value:["email_sp61_status_id",""]},
{name:"email.countrysampler-news.com", value:["email_sp62_status_id",""]},
{name:"goodolddaysnewsletter.com", value:["email_sp63_status_id",""]},
{name:"anniesquiltersworldnewsletter.com", value:["email_sp64_status_id",""]},
{name:"anniestalkingcrochetnewsletter.com", value:["email_sp65_status_id",""]},
{name:"anniescreativewomannewsletter.com", value:["email_sp66_status_id",""]},
{name:"anniescreativeknittingnewsletter.com", value:["email_sp67_status_id",""]},
{name:"anniessewingsavvynewsletter.com", value:["email_sp68_status_id",""]},
{name:"e-patternscentral-daily-news.com", value:["email_sp69_status_id",""]},
{name:"anniesquiltsewdaily-news.com", value:["email_sp70_status_id",""]},
{name:"anniescardmakernewsletter.com", value:["email_sp71_status_id",""]},
{name:"anniessimplybeadsnewsletter.com", value:["email_sp72_status_id",""]},
{name:"anniescrochetcraft-news.com", value:["email_sp73_status_id",""]},
{name:"e-patternscentral-quilt-news.com", value:["email_sp74_status_id",""]},
{name:"anniesgoodolddaysstoredaily-news.com", value:["email_sp75_status_id",""]},
{name:"anniesquiltdaily-news.com", value:["email_sp76_status_id",""]},
{name:"anniescrochetknitdownload-news.com", value:["email_sp77_status_id",""]},
{name:"anniesquiltsewdownloads-news.com", value:["email_sp78_status_id",""]},
{name:"anniesknityarndaily-news.com", value:["email_sp80_status_id",""]},
{name:"anniescrochetloversdaily.com", value:["email_sp81_status_id",""]},
{name:"annieslovetoknit.com", value:["email_sp82_status_id",""]},
{name:"annieslovetoquilt.com", value:["email_s83_status_id",""]},
{name:"anniescrochetdaily-news.com", value:["email_sp84_status_id",""]},
{name:"e-patternscentral-crochet-news.com", value:["email_sp85_status_id",""]},
{name:"e-patternscentral-knitting-news.com", value:["email_sp86_status_id",""]},
{name:"anniescreativecards.com", value:["email_sp87_status_id",""]},
{name:"anniesplasticcanvaslovers.com", value:["email_sp88_status_id",""]},
{name:"anniesbeadsandjewelry.com", value:["email_sp89_status_id",""]},
{name:"anniesonlineclassdaily-news.com", value:["email_sp90_status_id",""]},
{name:"anniesknitandcrochetnownewsletter.com", value:["email_sp91_status_id",""]},
{name:"anniescrossstitchneedlework.com", value:["email_sp92_status_id",""]},
{name:"anniesjustcrossstitchnewsletter.com", value:["email_sp93_status_id",""]},
{name:"anniessimplysewing.com", value:["email_sp94_status_id",""]},
{name:"anniesfabrictrendreport.com", value:["email_sp95_status_id",""]},
{name:"anniesyarntrendreport.com", value:["email_sp96_status_id",""]},
{name:"anniesatticmysteries-news.com", value:["email_sp97_status_id",""]},
{name:"anniescreativepainter-news.com", value:["email_sp98_status_id",""]},
{name:"anniescreativewomanclub-news.com", value:["email_sp99_status_id",""]},
{name:"anniessecretofthequilt-news.com", value:["email_sp100_status_id",""]},
{name:"anniesmysteriesunraveled-news.com", value:["email_sp101_status_id",""]},
{name:"countrysamplermagazine-news.com", value:["email_sp102_status_id",""]},
{name:"clotilde-news.com", value:["email_sp103_status_id",""]},
{name:"CountrySamplerStyleToSpare-news.com", value:["email_sp104_status_id",""]},
{name:"CountrySamplerIssuePreview-news.com", value:["email_sp105_status_id",""]}
]
<img src="http://links.anniesatticmysteries-news.com/rts/open.aspx?tp=i-4p-6o-y-1o-1c-G-5ipHQ" height="1" width="1" style="display:none">
</body>
</html>
什么是
<img src="http://links.anniesatticmysteries-news.com/rts/open.aspx?tp=i-4p-6o-y-1o-1c-G-5ipHQ" height="1" width="1" style="display:none">
</body>
</html>
在那里???使用fiddler检查您的HTTP。