Create Png by sending json to php using ajax [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I am trying to make an app where users can crop the image then save then can download it, but after cropping when i click on save button the png image created is of 0kb...
what could be the error?
this is my js file
function getIndex(e) {
var t = c.getObjects();
for (var n in t) {
if (t[n] == e) {
return n
}
}
}
function loadingShow(e) {
$("#overlay_loading").show();
$("#overlay_loading #load_message").html(e);
$("body").css("overflow", "hidden")
}
function loadingHide() {
$("#overlay_loading").hide();
$("body").css("overflow", "inherit")
}
function getData() {
var e = $("body").data("dats")
}
function reloadThumbs(e) {
if (!cropping) {
var t = $($("#object_layers li").get().reverse());
if (e) {
var n = [];
var r = getIndex(e);
n[r] = e
} else {
var n = c.getObjects();
var i = "";
if (n.length !== t.length) {
$("#object_layers").empty();
for (var s = 0; s < n.length; s++) {
var o = $('<image width="120" height="75" />').attr("src", i);
$("<li/>").prependTo("#object_layers").append(o)
}
t = $($("#object_layers li").get().reverse())
}
}
for (s in n) {
if (n[s] !== undefined) {
var u = fabric.document.createElement("canvas");
if (!u.getContext && typeof G_vmlCanvasManager != "undefined") {
G_vmlCanvasManager.initElement(u)
}
u.width = $("#cc").width();
u.height = $("#cc").height();
fabric.util.wrapElement(u, "div");
var a = new fabric.Canvas(u);
a.backgroundColor = "transparent";
var f = n[s].isActive();
a.add(n[s]);
a.renderAll();
var i = a.toDataURLWithMultiplier("png", .35101058);
if (f) {}
$(t.get(s)).find("img").attr("src", i);
$("#object_layers li").click(function () {
$("#object_layers li").removeClass("layer_selected");
$(this).addClass("layer_selected")
})
}
}
reloadData()
}
}
function reloadLayers() {
$($("#object_layers li").get().reverse()).each(function () {
if ($(this).data("object") !== undefined) c.bringToFront($(this).data("object"))
});
reloadData()
}
function reloadData() {
var e = c.getObjects();
var t = $($("#object_layers li").get().reverse());
for (var n in e) {
if (e[n] !== undefined) {
$(t.get(n)).data("object", e[n])
}
}
c.selection = false
}
function cropStart() {
cropping = true;
c.forEachObject(function (e) {
e.selectable = false
});
var e = actObj;
var t = {
left: 450,
top: 150,
width: 300,
height: 200
};
console.log(t);
cropObject = new Crop({
left: t.left,
top: t.top,
fill: "rgba(255,255,255,0)",
width: t.width,
height: t.height
});
c.add(cropObject);
c.deactivateAll();
cropObject.selectable = true;
c.setActiveObject(cropObject);
c.bringToFront(cropObject);
c.renderAll();
$("#crop_control").show()
}
function crop() {
var e = cropObject.width * cropObject.scaleX;
var t = cropObject.height * cropObject.scaleY;
var n = cropObject.left - e / 2;
var r = cropObject.top - t / 2;
var i = actObj;
i.clone(function (s) {
var o = fabric.document.createElement("canvas");
if (!o.getContext && typeof G_vmlCanvasManager != "undefined") {
G_vmlCanvasManager.initElement(o)
}
o.width = e;
o.height = t;
fabric.util.wrapElement(o, "div");
var u = new fabric.Canvas(o);
u.backgroundColor = "transparent";
s.setOpacity(1);
u.add(s);
s.left -= n;
s.top -= r;
u.renderAll();
var a = u.toDataURL();
var f = $("<img src=" + a + " />").get(0);
i.scaleX = 1;
i.scaleY = 1;
i.setElement(f);
i.width = e;
i.height = t;
i.setAngle(0);
c.setActiveObject(i);
c.renderAll();
setTimeout(function () {
c.renderAll();
reloadThumbs(i)
}, 100);
reloadThumbs()
});
cropFinish()
}
function cropFinish() {
$("#crop_control").hide();
$(".ct").removeAttr("disabled");
$("#object_layers").sortable("enable");
cropping = false;
c.remove(cropObject);
cropObject = null
}
var cropping = false;
var c = new fabric.Canvas("cc");
var start, set = "personal";
c.setOverlayImage("img/foreground-personal.png", c.renderAll.bind(c));
c.backgroundColor = "rgba(59,89,152,1)";
$(function () {
if (window.File && window.FileReader && window.FileList && window.Blob) {} else {}
$("#fileupload").fileupload({
add: function (e, t) {
if (typeof FileReader !== "undefined") {
$(t.files).each(function (e) {
var t = this;
var n = new FileReader;
n.onload = function (e) {
var t = e.target.result;
fabric.Image.fromURL(t, function (e) {
if (e.getWidth() > 800) {
e.scaleToWidth(800)
}
if (e.getHeight() > 400) {
e.scaleToHeight(400)
}
c.add(e);
e.setActive(true);
c.centerObjectH(e).centerObjectV(e);
e.setCoords();
c.renderAll();
var n = $('<image width="120" height="55" />').attr("src", t);
$("<li/>").prependTo("#object_layers").append(n);
reloadThumbs()
})
};
n.readAsDataURL(t)
})
} else {
t.submit()
}
},
dataType: "json",
done: function (e, t) {
$.each(t.result, function (e, t) {
$("<p/>").text(t.name).appendTo(document.body);
fabric.Image.fromURL(t.url, function (e) {
var t = e.set({
left: 110,
top: 75
}).scale(.7);
c.add(t).renderAll()
})
})
}
});
$(document).keydown(function (e) {
if (e.which == 46 && !cropping) {
var t = c.getActiveObject();
if (t) {
c.remove(t);
reloadThumbs()
}
}
});
$("#save").click(function () {
var e = JSON.stringify(c);
loadingShow("Saving... Please Wait...");
$.ajax({
type: "POST",
url: "ajax.php",
data: {
d: e
}
}).done(function (e) {
loadingHide();
alert("Data Saved!")
})
})
});
c.observe("object:modified", function (e) {
reloadThumbs(e.target)
});
c.observe("object:selected", function (e) {
var t = e.target;
var n = getIndex(t);
if (t.type == "image") {
$(".ot").attr("disabled", "disabled").val("");
$(".oi").removeAttr("disabled")
} else if (t.type == "text") {
$(".oi").attr("disabled", "disabled");
$(".ot").removeAttr("disabled");
var r = t.toObject();
var i = t.getFill();
if (start && r.text == "Click here to start") {
c.clear();
reloadThumbs();
start = false
}
$("#text_text").val(r.text);
$("#text_color").val(i.toUpperCase());
$("#text_font").val(r.fontFamily)
}
});
c.observe("selection:cleared", function (e) {
$(".ot").val("").attr("disabled", "disabled");
$(".oi").val("").attr("disabled", "disabled")
});
var cropObject = null;
var actObj;
$("#image_crop").click(function () {
$(this).attr("disabled", "disabled");
$(".ct").attr("disabled", "disabled");
$("#object_layers").sortable("disable");
actObj = c.getActiveObject();
cropStart();
return false
});
$("#crop_ok").click(function () {
crop();
c.forEachObject(function (e) {
e.selectable = true
})
});
$("#crop_cancel").click(function () {
cropping = false;
cropFinish();
c.setActiveObject(actObj);
c.forEachObject(function (e) {
e.selectable = true
});
return false
})
this is the save code in js using ajax
$("#save").click(function () {
var e = JSON.stringify(c);
loadingShow("Saving... Please Wait...");
$.ajax({
type: "POST",
url: "ajax.php",
data: {
d: e
}
}).done(function (e) {
loadingHide();
alert("Data Saved!")
})
})
});
this my php file
echo $_POST['e'];
echo json_decode($_POST['e']);
echo var_dump(json_decode($_POST['e']));
$name=time();
file_put_contents("uploads/" . $name . ".png", $data);

Your posted data has a key d but you are trying to read from e which doesn't have a value.
Even if that wasn't the case, then I'm pretty sure that no valid JSON data will decode to be a PNG binary anyway.

Related

How to take screen shot of a web page in PHP and show it in model popup and submit it into database

function screenshot(){
html2canvas(document.body).then(function(canvas) {
//document.body.appendChild(canvas);
// Get base64URL
var base64URL = canvas.toDataURL('').replace( 'image/octet-stream');
// AJAX request
$.ajax({
url: 'screen_shot.php',
type: 'post',
data: {image: base64URL},
success: function(data){
alert('Upload successfully');
}
});
});
}
1) You can use HTML5 & javaScript to take screenshots. This will work for sure. check more details
here
(function (exports) {
function urlsToAbsolute(nodeList) {
if (!nodeList.length) {
return [];
}
var attrName = 'href';
if (nodeList[0].__proto__ === HTMLImageElement.prototype
|| nodeList[0].__proto__ === HTMLScriptElement.prototype) {
attrName = 'src';
}
nodeList = [].map.call(nodeList, function (el, i) {
var attr = el.getAttribute(attrName);
if (!attr) {
return;
}
var absURL = /^(https?|data):/i.test(attr);
if (absURL) {
return el;
} else {
return el;
}
});
return nodeList;
}
function screenshotPage() {
urlsToAbsolute(document.images);
urlsToAbsolute(document.querySelectorAll("link[rel='stylesheet']"));
var screenshot = document.documentElement.cloneNode(true);
var b = document.createElement('base');
b.href = document.location.protocol + '//' + location.host;
var head = screenshot.querySelector('head');
head.insertBefore(b, head.firstChild);
screenshot.style.pointerEvents = 'none';
screenshot.style.overflow = 'hidden';
screenshot.style.webkitUserSelect = 'none';
screenshot.style.mozUserSelect = 'none';
screenshot.style.msUserSelect = 'none';
screenshot.style.oUserSelect = 'none';
screenshot.style.userSelect = 'none';
screenshot.dataset.scrollX = window.scrollX;
screenshot.dataset.scrollY = window.scrollY;
var script = document.createElement('script');
script.textContent = '(' + addOnPageLoad_.toString() + ')();';
screenshot.querySelector('body').appendChild(script);
var blob = new Blob([screenshot.outerHTML], {
type: 'text/html'
});
return blob;
}
function addOnPageLoad_() {
window.addEventListener('DOMContentLoaded', function (e) {
var scrollX = document.documentElement.dataset.scrollX || 0;
var scrollY = document.documentElement.dataset.scrollY || 0;
window.scrollTo(scrollX, scrollY);
});
}
function generate() {
window.URL = window.URL || window.webkitURL;
window.open(window.URL.createObjectURL(screenshotPage()));
}
exports.screenshotPage = screenshotPage;
exports.generate = generate;
})(window);
2) You can also use html2canvas below is the simple example of how to implement.
JS
html2canvas(document.querySelector("#capture")).then(canvas => {
document.body.appendChild(canvas)
});
HTML
<div id="capture" style="padding: 10px; background: #f5da55">
<h4 style="color: #000; ">Hello world!</h4>
</div>
download & include in the head section
//*
<script src="Scripts/jquer_latest_2.11_.min.js" type="text/javascript"></script>
<script src="Scripts/html2canvas.js" type="text/javascript"></script>
//*

How to get origial value in jquery crop image

I downloaded one jquery crop image module it is working fine,actually i want now that original image value,from this code i got only for cropped image value,when i upload one image means i want store that image in without crop,actually i don't know how to get that value in this code reference URL http://fengyuanchen.github.io/cropper/v1.0.0/
$(function () {
'use strict';
var console = window.console || { log: function () {} };
var $body = $('body');
// Tooltip
// $('[data-toggle="tooltip"]').tooltip();
// $.fn.tooltip.noConflict();
// $body.tooltip();
// Demo
// ---------------------------------------------------------------------------
(function () {
var $image = $('.img-container > img');
console.log($image);
var $actions = $('.docs-actions');
var $download = $('#download');
//console.log($download);
var $dataX = $('#dataX');
var $dataY = $('#dataY');
var $dataHeight = $('#dataHeight');
var $dataWidth = $('#dataWidth');
var $dataRotate = $('#dataRotate');
var $dataScaleX = $('#dataScaleX');
var $dataScaleY = $('#dataScaleY');
var options = {
aspectRatio: 16 / 9,
preview: '.img-preview',
crop: function (e) {
$dataX.val(Math.round(e.x));
$dataY.val(Math.round(e.y));
$dataHeight.val(Math.round(e.height));
$dataWidth.val(Math.round(e.width));
$dataRotate.val(e.rotate);
$dataScaleX.val(e.scaleX);
$dataScaleY.val(e.scaleY);
}
};
$image.on({
'build.cropper': function (e) {
//console.log(e.type);
},
'built.cropper': function (e) {
//console.log(e.type);
},
'cropstart.cropper': function (e) {
//console.log(e.type, e.action);
},
'cropmove.cropper': function (e) {
//console.log(e.type, e.action);
},
'cropend.cropper': function (e) {
//console.log(e.type, e.action);
},
'crop.cropper': function (e) {
// console.log(e.type, e.x, e.y, e.width, e.height, e.rotate, e.scaleX, e.scaleY);
},
'zoom.cropper': function (e) {
console.log(e.type, e.ratio);
}
}).cropper(options);
// Methods
$actions.on('click', '[data-method]', function () {
var $this = $(this);
var data = $this.data();
var $target;
var result;
if ($this.prop('disabled') || $this.hasClass('disabled')) {
return;
}
if ($image.data('cropper') && data.method) {
data = $.extend({}, data); // Clone a new one
if (typeof data.target !== 'undefined') {
$target = $(data.target);
if (typeof data.option === 'undefined') {
try {
data.option = JSON.parse($target.val());
} catch (e) {
//console.log(e.message);
}
}
}
result = $image.cropper(data.method, data.option, data.secondOption);
if (data.flip === 'horizontal') {
$(this).data('option', -data.option);
}
if (data.flip === 'vertical') {
$(this).data('secondOption', -data.secondOption);
}
if (data.method === 'getCroppedCanvas' && result) {
$('#getCroppedCanvasModal').modal().find('.modal-body').html(result);
if (!$download.hasClass('disabled')) {
$download.attr('href', result.toDataURL());
console.log(result.toDataURL());//data:base64 ans
$(document).ready(function(){
$('#crop').click(function(){
//console.log('ok');
$.ajax({
type:'POST',
url: "crop_image_insert.php",
data: ({'crop': result.toDataURL()}),
success:function(data){
console.log(data);
if(data == 'SUCCESS'){
window.location.assign('php/timeline.php?id=<?php echo $ssmid;?>');
}
},
error:function(error){
alert('n');
}
});
});
});
}
}
if ($.isPlainObject(result) && $target) {
try {
$target.val(JSON.stringify(result));
} catch (e) {
}
}
}
});
// Keyboard
$body.on('keydown', function (e) {
if (!$image.data('cropper') || this.scrollTop > 300) {
return;
}
switch (e.which) {
case 37:
e.preventDefault();
$image.cropper('move', -1, 0);
break;
case 38:
e.preventDefault();
$image.cropper('move', 0, -1);
break;
case 39:
e.preventDefault();
$image.cropper('move', 1, 0);
break;
case 40:
e.preventDefault();
$image.cropper('move', 0, 1);
break;
}
});
// Import image
var $inputImage = $('#inputImage');
var URL = window.URL || window.webkitURL;
var blobURL;
if (URL) {
$inputImage.change(function () {
var files = this.files;
var file;
if (!$image.data('cropper')) {
return;
}
if (files && files.length) {
file = files[0];
if (/^image\/\w+$/.test(file.type)) {
blobURL = URL.createObjectURL(file);
$image.one('built.cropper', function () {
URL.revokeObjectURL(blobURL); // Revoke when load complete
}).cropper('reset').cropper('replace', blobURL);
$inputImage.val('');
} else {
$body.tooltip('Please choose an image file.', 'warning');
}
console.log($inputImage.val(''));
}
});
} else {
$inputImage.prop('disabled', true).parent().addClass('disabled');
}
}());
});

Laravel filter redirect crashed web page

I am using Laravel 4.1 and created a global filter which redirects to a particular page if any of the following value is null.
Name
email
DOB
Religion
Caste
In the above values Caste is populated dynamically. When the religion value is changed. Everything was working fine With the below code in filter.php:
if (is_null(value->name)) {
return Redirect::to('confirm');
}
if (is_null(value->email)) {
return Redirect::to('confirm');
}
if (is_null($value->dob) {
return Redirect::to('confirm');
}
But when I added Religion or caste or both. The jQuery in the page crashes that is the dropdown isn't populating properly and the entire browser hangs.
if (is_null(value->name)) {
return Redirect::to('confirm');
}
if (is_null(value->email)) {
return Redirect::to('confirm');
}
if (is_null($value->dob) {
return Redirect::to('confirm');
}
if (is_null($value->religion) {
return Redirect::to('confirm');
}
if (is_null($value->caste) {
return Redirect::to('confirm');
}
I don't why it is happening; the first three work completely fine.
jQuery:
var Religion = '#Religion' ;
var Caste = '#Caste' ;
var caste = new Array();
var usr ;
$(function () {
$.ajaxSetup({
async: false
});
usr = getUser();
if(!$.isEmptyObject(usr))
{
var data = getCasteForReligion(usr.religionid) ;
if (data != null) {
// alert(data);
caste = new Array();
for (var i = 0; i < data.length; i++) {
caste.push(data[i]);
}
loadCastes(caste);
}
if(user.casteid != null)
{
$(Caste).val(usr.casteid).trigger('list:updated');
}
}
$(Religion).change(function () {
if ($(Religion).val() != "") {
var data = getCasteForReligion($(Religion).val());
if (data != null) {
// alert(data);
caste = new Array();
for (var i = 0; i < data.length; i++) {
caste.push(data[i]);
}
loadCastes(caste);
}
}
else {
}
});
});
function getCasteForReligion(religionid) {
var result;
$.get('/getCastes',
{ religionId : religionid },
function(data) {
result = data;
});
return result;
}
function getUser() {
var result;
$.get( '/User',
{ },
function(data) {
result = data;
});
return result;
}
//Generate Products variant for Indent
function loadCastes(castlst) {
$(Caste).find('option').remove();
$(Caste).val('').trigger('list:updated');
$(Caste).append(new Option("--Select--", "")).trigger('list:updated');
for (var i = 0; i < castlst.length; i++) {
$(Caste).append(new Option(castlst[i].name, castlst[i].id)).trigger('list:updated');
}
}

How to stay on same tab in bootstrap3 in zf2?

I used bootstrap 3 tabs in php but when i refresh my previous tab forms fields shown empty,How i show these fields after refreshing page?
Here is my code:
var hash = window.location.hash;
$('#signup_tabs_group a[href="' + hash + '"]').tab('show');
// Get form data and enforce tab wise validation
var form_data = $.parseJSON($('form').attr('data-elements'));
$("#continue_to_account").click(function (e) {
if ($("#password1").val() != '' && $("#password1").val() != $("#password2").val()) {
popoverContent('password2', "Please Confirm Password.", "right");
$("#password2").popover('show');
$("#password2").addClass('mypopover');
$("#password2").focus();
return false;
} else {
$("#password2.mypopover").popover('hide');
}
if ($("#email").val() != '' && $("#email").val() != $("#email2").val()) {
popoverContent ('email2', "Please Confirm Email.", "right");
$("#email2").popover('show');
$("#email2").focus();
$("#email2").addClass('mypopover');
return false;
} else {
$("#email2.mypopover").popover('hide');
}
$("ul.nav-tabs > li > a").on("shown.bs.tab", function (e) {
var id = $(e.target).attr("href").substr(1);
window.location.hash = id;
});
var custom_form = [];
var required_elements = ['email', 'email2', 'username', 'password1', 'password2'];
for (var c = 0; c < form_data.length; c++) {
if (typeof(form_data[c].name) != "undefined" && required_elements.indexOf(form_data[c].name) != -1) {
custom_form[c] = form_data[c];
}
}
if (validations(custom_form, $('form'), $(this), 'right') != false) {
e.preventDefault();
$('#signup_tabs_group a[href="#contact"]').tab('show');
return true;
}
return false;
});
$("#back_to_account").click(function (e) {
e.preventDefault();
$('#signup_tabs_group a[href="#account"]').tab('show');
});
$("#continue_to_website").click(function (e) {
var custom_form = [];
var required_elements = [{'contact_first_name': true}, {'contact_last_name': true}, {'country': true}, {'account_type': true}, {'address1': true}, {'address2': false}, {'address3': false}, {'city': true}, {'state': false}, {'zipcode': true}, {'phone_code': false}, {'phone_number': true}, {'fax': false}, {'currency': false}];
if (
typeof($('input[name=account_type]:checked').val()) != 'undefined' &&
$('input[name=account_type]:checked').val() == 'company'
) {
required_elements.push({'company_name': true});
}
//return false;
for (var c = 0; c < form_data.length; c++) {
if (
typeof(form_data[c].name) != "undefined" &&
typeof(form_data[c].validation) != "undefined" &&
typeof(form_data[c].validation.required) != "undefined"
) {
for (var i = 0; i < required_elements.length; i++) {
if (typeof(required_elements[i][form_data[c].name]) != 'undefined') {
form_data[c].validation.required = required_elements[i][form_data[c].name];
custom_form[c] = form_data[c];
break;
}
}
}
}
if (validations(custom_form, $('form'), $(this), 'right') != false) {
e.preventDefault();
$('#signup_tabs_group a[href="#website"]').tab('show');
return true;
}
return false;
});
$("#back_to_website").click(function (e) {
e.preventDefault();
$('#signup_tabs_group a[href="#contact"]').tab('show');
});
$('input[name=account_type]').change(function() {
if ($('input[name=account_type]:checked').val() == 'company') {
$('.company-label').removeClass('hidden');
} else {
$('.company-label').addClass('hidden');
$('#company_name').val('');
if ($('#company_name').hasClass('mypopover')) {
$('#company_name').popover('hide');
$('#company_name').popover('disable');
}
}
});
// jQuery International Telephone Input With Flags and Dial Codes
$("#phone_code").intlTelInput({
defaultCountry: "gb"
});
//Validation
$(".validate_button").click(function(e){
var words = $('#description').val().split(/\b[\s,\.-:;]*/);
if (words.length > 100) {
words.splice(100);
$('#description').val(words.join(" "));
}
var custom_form3 = [];
var required_elements = ['website_name', 'website_url', 'unique_visitors', 'audience_geo', 'audience_interests', 'website_content', 'advertising_type', 'other_affiliate_member', 'working_with_qs', 'description', 'hear_about_us', 'accept_terms'];
for (var c = 0; c < form_data.length; c++) {
if (typeof(form_data[c]) != "undefined" && typeof(form_data[c].name) != "undefined" && required_elements.indexOf(form_data[c].name) != -1) {
custom_form3[c] = form_data[c];
}
}
if (validations(custom_form3, $('form'), $(this), 'right') != false) {
return true;
}
How i show form fields after refreshing page?
It's rather pure JS/jQuery question than ZF2 related.
I solved this problem in such a way:
$(function(){
var url = document.location.toString();
if (url.match('#')) {
$('.nav-tabs a[href=#'+url.split('#')[1]+']').tab('show') ;
}
$('.nav-tabs a').on('shown.bs.tab', function (e) {
window.location.hash = e.target.hash;
});
});
i'm looking for tabs which 'a' element href ends with hash from url and then i show them. I also set in window url hash component when someone click on tab so after that someone refresh page it bring him last viewed tab.

appending the div after redirect the page by window.location

In this code i check the page name and then if i find that page, i redirect that page to the other packDetails.php and then want to append the div having the code in dataLoad(). function.
have a look to the code :
$(document).ready(function(){
$('#resultDiv').hide();
$('#allpacks').hide();
var filename = window.location.href.substr(window.location.href.lastIndexOf("/")+1);
$('#searchButton').click(function(){
if(filename != 'packDetails.php')
{
window.location='packDetails.php';
window.onload = function () {
alert('saeed');
}();
}
else{
dataLoad();
}
});
});
dataLoad:-
function dataLoad()
{
$('#showAll').show(1500);
$('#searchResults').html('');
var searchValue=$('#searchb').val();
$('#searchName').html(searchValue);
if(searchValue=='')
{
alert("Please enter a valid keyword");
}
else{
$('#searchContent').show();
$('#outerDiv').hide();
$('#result').html('');
$.ajax({
url:'SolrResponse.php',
data:{search: searchValue},
success:function(responseText)
{
$('#resultDiv').show();
$('#allpacks').hide();
var data= responseText.substring(0, responseText.length - 1);
var object= JSON.parse(data);
var response= object.response;
var div=$('<div></div>');
var docs= response.docs;
resultData=docs;
var length= docs.length;
if(length>0)
{
for(var i=0; i<length; i++)
{
var mainDiv=$('<div id="mainDiv"></div>');
var packName=$('<div id="namePack">'+docs[i].packName+'</div>');
var packDesc=$('<div id="descPack">'+docs[i].packDescription+'</div>');
var packVer=$('<div id="verPack">Pack Version: '+docs[i].packVersion+'</div>');
var packAuth=$('<div id="authPack">Author: '+docs[i].packAuthor+'</div>');
var entityN= docs[i].entityName;
var entityD= docs[i].entityDescription;
var entityT=docs[i].entityType;
var entityDet=$('<div id="entityDet"></div>');
for(var j=0;j<entityN.length;j++)
{
if((entityN[j].toUpperCase()).indexOf(searchValue.toUpperCase()) > -1)
{
entityN[j]=entityN[j].replace(searchValue, '<span>'+searchValue+'</span>');
var entityName=$('<div id="nameEn">'+entityN[j]+' ('+entityT[j]+')</div>');
entityDet.append(entityName);
}
else
{
if((entityD[j].toUpperCase()).indexOf(searchValue.toUpperCase()) > -1)
{
entityD[j]=entityD[j].replace(searchValue, '<span>'+searchValue+'</span>');
var entityName=$('<div id="nameEn">'+entityD[j]+' ('+entityT[j]+')</div>');
entityDet.append(entityName);
}
}
}
mainDiv.append(packName);
mainDiv.append(packDesc);
mainDiv.append(packVer);
mainDiv.append(packAuth);
mainDiv.append(entityDet);
$('#searchResults').append(mainDiv);
}
}
else
{
$('#searchResults').html("No Data Found");
}
}
});
}
}

Categories