在window.location重定向页面后附加div

时间:2014-05-06 11:19:46

标签: php jquery ajax

在这段代码中,我检查页面名称,然后如果我找到该页面,我将该页面重定向到另一个packDetails.php,然后想要在dataLoad()中附加代码的div。功能。     看看代码:

 $(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");
            }

          }
        });
      }
}

0 个答案:

没有答案