从阿贾克斯返回访问HTML和JSON数据 [英] Access both html and json data returned from ajax
本文介绍了从阿贾克斯返回访问HTML和JSON数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个AJAX页面返回一些数据,其中包含了HTML和JSON data.I不知道要使用的数据类型的内容提取从阿贾克斯返回的组合。目前我使用AJAX数据类型:HTML
I have an ajax page to return some data which contains a mix of HTML and Json data.I dont know which data type to use to extract the contents returned from ajax. Currently I used ajax dataType: 'html'
请帮我提取AJAX HTML和JSON数据。
Kindly help me to extract the HTML and Json data from ajax.
我回到下面的内容从阿贾克斯
I returned the below content from ajax
'{"id" :"Test_p","label" :"Test Property"},{"id" :"29772_l","label" :"Test Locality"},{"id" :"Universal Infrastructure Development Company_c","label" :"Test Company"},{"id" :"Test_p","label" :"Vijay Property"},{"id" :"29772_l","label" :"Vijay Locality"},{"id" :"Universal Infrastructure Development Company_c","label" :"VJ Company"}'
请找我的HTML内容
<div data-ride="carousel" class="carousel slide show-number-count featured-carousel" id="carousel-ready-to-move-in" data-interval="false">
<div role="listbox" class="carousel-inner col-max-10 col-center carousel-area" id="readytomovein"><div id="rtmicarousel" class="item active">
<div class="row" id="ready_to_move_in_row"><div class="col-sm-2 col-xs-2">
<div class="col-inner border prop-grid font-small bg-white">
<a href="apartment-for-sale-in-ambattur-chennai-by-loyal-housing-developments-pvt-ltd-3376939" target="_blank">
<img width="200" height="120" alt="" src="http://imgs.indiaproperty.com/images/ip-no-logo2.jpg" class="lazy-load display-block">
<div class="nbh-vtext">Aishwarryam</div>
<p class="color-primary">
<span class="font-semi-bold color-green-l show">₹35.46 Lacs-39.35 L..</span>
<span class="font-semi-bold show color-blue">by Loyal Housing D..</span>Ambattur
</p>
<div class="property-details clearfix font-x-small color-primary">
<span class="pull-left">2 BHK</span>
<span class="pull-right"> </span>
</div>
</a>
</div>
</div></div></div></div>
<a data-slide="prev" role="button" href="#carousel-ready-to-move-in" class="left carousel-nav color-primary">
<i class="icon-dir-left"></i>
</a>
<a data-slide="next" role="button" href="#carousel-ready-to-move-in" class="right carousel-nav color-primary" id="next_slide_id">
<i class="icon-dir-right"></i>
</a>
<div class="slide-number"></div>
</div>
我要将此数据转换为在阿贾克斯成功功能的JavaScript对象数组
I have to convert this data as javascript array object in ajax success function
感谢。
推荐答案
也许是这样的:的http://的jsfiddle .NET / IonDen / 2L2gnxae /
// Some test ajax result
var result = '{"somejson", "value"}';
result += '<div>Some html</div>';
console.log(result);
// split result to json and html
var sl = result.indexOf("<");
var json = result.slice(0, sl);
var html = result.slice(sl);
console.log(json);
console.log(html);
这篇关于从阿贾克斯返回访问HTML和JSON数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文