0

i m a beginner...

here i m using the jquery for showing search results load in ajax type...

so here i have to pass the keyword and the id of the last result when clicked on the show more result...

but in the jquery that i found, it works on only id... and here i have to pass id and key... and here i have passed the them but now in the jquery i need to split the passed id in jquery...

here i need only id for removing that is in if condition but want to pass both id and keyword...

here is the code....

<script>
$('.more').live("click",function() 
{
//here id value is suppose 25(space)nike but i want 25 for if(ID)
var ID = $(this).attr("id");
if(ID) 
{
   $("#more"+ID).html('<img src="load/moreajax.gif" />');
   $.ajax({
   type: "POST",
   url: "load/ajax_more_search.php",
   data: "lastmsg="+ ID, 
   cache: false,
   success: function(html){
   $("div#updates").append(html);
   $("#more"+ID).remove();
 }
 });
 }
 else
 {
   $(".morebox").html('The End');
 }
 return false;
 });
 });
   </script>

also i need to pass the keyword too....

will split work for this... or it onlr works for urls...?

thanking you

1
  • 1
    '25 nike'.split(' ') == ['25','nike']
    – biziclop
    Nov 5, 2011 at 9:17

2 Answers 2

0

Yes split will work

var arr= ID.split(' ');
alert(arr[0]); // It will give you a ID
alert(arr[1]); // It will give you a Keyword

EDIT:

Yes your code is right but if you you need that keyword field on

ajax_more_search.php

then you have to pass it with ID. For that Change your code.

data: "lastmsg="+ ID, 

change this with.

{lastmsg : ID, keyword : arr[1] },
3
  • Thank you... now i change the code to var ID = $(this).attr("id"); var arr= ID.split(' '); var CK = arr[0]; if(CK) { $("#more"+ID).html('<img src="load/moreajax.gif" />'); $.ajax({ type: "POST", url: "load/ajax_more_search.php", data: "lastmsg="+ ID, cache: false, success: function(html){ $("div#updates").append(html); $("#more"+ID).remove(); } }); } else { $(".morebox").html('The End'); } but still the same error comes... is my logic wrong....?
    – Akjethwani
    Nov 5, 2011 at 9:35
  • yes.... thank you.... but the problem is not with passing rather its with checking the id in the script here my search is working properly.... and both the key and id are passed... the only thing that is going wrong is with the button... when the search algo do not find any more results from db... the button should not be mentioned and instead it should show "The End" this happens due to script which is checked by if condition as mentioned in code above... it runs when i only pass the id but do not run when i pass both...!!!!
    – Akjethwani
    Nov 5, 2011 at 10:05
  • OMG.... the thing that you mentioned early was correct and now it is working.... i changed the code to... var ID = $(this).attr("id"); var arr= ID.split(' '); var CK = arr[0]; if(CK) { $("#more"+ID).html('<img src="load/moreajax.gif" />'); $.ajax({ type: "POST", url: "load/ajax_more_search.php", data: "lastmsg="+ ID, cache: false, success: function(html){ $("div#updates").append(html); $("#more"+CK).remove(); } }); } else { $(".morebox").html('The End'); } previously i forgot to change ID to CK in the Code $("#more"+ID).remove(); thanking you... regards...
    – Akjethwani
    Nov 5, 2011 at 10:15
0

If your ID contains space character - something is wrong with your code :)

Don't use spaces in your ID. Use underscores instead. But this is not perfect too. It's correct to use data-id attribute in this case. ID or class must be used only if you need to style this element, or identify it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.