# in url prevents ajax

Last post 05-10-2008 12:16 PM by stmarti. 5 replies.

Sort Posts:

  • # in url prevents ajax

    05-08-2008, 1:46 PM
    • Loading...
    • uini
    • Joined on 12-13-2006, 12:51 PM
    • Posts 18

    Hello
    I figgured that sometimes when the url gets # in the end,
    ajax stops working.
    For example, in my website, there is a url:
    http://www.balcon.co.il/index.aspx?ln=he
    In this page there is a list, when you click for details , you get them by ajax.
    The problem is that after the first click, the url becomes:
    http://www.balcon.co.il/index.aspx?ln=he#
    I think that the: # prevents the ajax.
    Could someone help me ?
    Thanks in advance.

  • Re: # in url prevents ajax

    05-08-2008, 3:58 PM
    • Loading...
    • stmarti
    • Joined on 06-06-2006, 12:20 PM
    • Posts 539

    Hi,

    I tested your page:

    - the details works in firefox, # doesn't matter

    - in ie6 the first popup works, but the second attemp fails with: "There was a problem with the request"

    You could eliminate the # from the url this way:

    use href="javascript:{}" instead of href="sharp (I cannot write here the sharp symbol because the stupid forum engine insert the page url before the symbol"

  • Re: # in url prevents ajax

    05-09-2008, 6:41 AM
    • Loading...
    • uini
    • Joined on 12-13-2006, 12:51 PM
    • Posts 18

    Well my problem is that the ajax post inserts to the url "#".
    This "#" ruins the whole process.
    You can also see that when the url is: http://www.balcon.co.il,
    after one click - the url becomes: http://www.balcon.co.il/#. In this case
    it is fine. (watch: "/#").
    The problem is when the "#" is added not after "/", but after a real parameter
    in the url: for an instance:
    The page: http://www.balcon.co.il/index.aspx?ln=en , after 1 click on "details" link
    becomes: http://www.balcon.co.il/index.aspx?ln=en# , and the ajax stops working.

    I do want to use href and not "window.open" , I do want it to be working in each one
    of the browsers, and I do want to use the ajax by updatepanel etc... it is very
    convenient.

    So the main question is why , by using ajax , the url gets this unnecessary "#".
    I'll appreciate any asistance.

  • Re: # in url prevents ajax

    05-09-2008, 7:06 AM
    • Loading...
    • stmarti
    • Joined on 06-06-2006, 12:20 PM
    • Posts 539

    Hi,

     

    uini:
    So the main question is why , by using ajax , the url gets this unnecessary "#".

    Because you add the # to the link, and not ajax. 

    You are using links in your gridview to show the details popup, here is some exact copy form your code which seen by the browser (you can see it with "view source" in the browser):

    ...

    <td>

    <a id="ctl00_ContentPlaceHolder1_gvAppartsList_ctl11_aMoreDetails" onclick="getAppartDetails('','7')" href="#">Details</a>
    </td>

    ... 

    This won't work, you need to change your template generation to get something like this (find your asp:hyperlink controls in the gridview template and change the href to "javascript:{}", that's all you need)

     

    <td>

    <a id="ctl00_ContentPlaceHolder1_gvAppartsList_ctl11_aMoreDetails" onclick="getAppartDetails('','7')" href="javascript:{}">Details</a>
    </td>

     
     

     

  • Re: # in url prevents ajax

    05-09-2008, 3:18 PM
    • Loading...
    • uini
    • Joined on 12-13-2006, 12:51 PM
    • Posts 18
    Hi, thanks for your reply.
    I put javascript:{} instead of the # as you can see in my view source, but it didn't solve the problem.
    The # is steal appears, I can't get rid of it.
    I solve the problem I had by removing the # from the url params in my code, but I'd prefer
    not to have to do it.
    Maybe you have another idea ?
    Thanks in advance!
  • Re: # in url prevents ajax

    05-10-2008, 12:16 PM
    • Loading...
    • stmarti
    • Joined on 06-06-2006, 12:20 PM
    • Posts 539

    uini:
    I put javascript:{} instead of the # as you can see in my view source, but it didn't solve the problem.
    The # is steal appears, I can't get rid of it.
     

    It still appears propably because your close "button" is a <a> link on the details view with a href="#", put href="javascript:{}" also there Big Smile (and change everywhere where you used href="#" for links with onclick)
     

Page 1 of 1 (6 items)