"/" bars and white space in Javascript function parameters

Asked

Viewed 626 times

0

erro na passagem de parametro

I need to pass a string that contains bars and white space.

<a href="javascript:carregaCliente('184/5 RB')"></a>

And in function

function carregaCliente(reg){

        console.log(reg);

        var map;

        $('#modalMapa').modal('show').on('shown.bs.modal', function () {
            map = new GMaps({
                div: '#map',
                center:{
                    lat: latitude,
                    lng: longitude
                },
                zoom: 17,
                scrollwheel: false,
                mapTypeId: google.maps.MapTypeId.ROADMAP,
                mapTypeControlOptions: {
                    style: google.maps.MapTypeControlStyle.DROPDOWN_MENU,
                    position: google.maps.ControlPosition.TOP_RIGHT
                },
                styles: [{
                    "featureType": "poi",
                    "stylers": [
                    { "visibility": "off" }]
                }]
            });

            map.addMarker({
                lat: latitude,
                lng: longitude,
                infoWindow: {
                    content: '<div style="padding-top:8px;color:#333;"><p>Cod Cliente: '+reg+'</p></div>'                   
                },
                animation: google.maps.Animation.DROP,
            }); 
            var markerInstance = map.markers[0];
            markerInstance.infoWindow.open(map, markerInstance);
        });         
    };

Simply does not load the page. the same happens if I put an ex date: 10/01/2016 14:00:50

  • 4

    uê, I don’t see anything wrong with your function, see how it works on jsfiddle: https://jsfiddle.net/jtgq900q/

  • Show how your parameter arrives in the function.

  • I did not detect the problem. Using bar / inside a string parameter does not influence anything. If it were counter-bar the story would be different.

  • @Gabrielheguedusch edited the question with the photo

  • Ta good, better then, put your customer charge function.

  • 1

    By the photo you can identify the problem. The string is being passed to the function to load without being in quotes.

  • 2

    In the code you posted <a href="javascript:carregaCliente('184/5 RB')"></a> is showing with simple quotes ('..') - '184/5 RB', however, your print is showing without, will not be missing in your original code?

  • I put the function @Antonioalexandre

  • @Ezequieltavares opens the source code of your page and checks if the code generated on your link is still <a href="javascript:loadClient('184/5 RB')">algoclicavel</a> or if it looks like this: <a href="javascript:loadable(184/5 RB)">algoclicable</a> (without single quotation marks around 184/5 RB). If you have no single quotes encapsulating the string this is the problem. Numbers can be passed without quotation marks, strings cannot.

  • @Antonioalexandre is without quotes the parameter. you are right but actually corrected the code and still not pass the parameter. in my case I did with a string but this client code will come dynamically through a php variable

  • Make your server side code generate with simple quotes and move on to the next problems, haha

  • If it came from the server side you should put it like this: <a href="javascript:carregaCliente('<?php echo $variavel; ?>')">texto</a>

Show 7 more comments

1 answer

-1

Whitespace as parameters are problematic. Try to replace whitespace with its UTF-8 equivalent: \u0020

  • Hi Vlademiro! You can add code to your reply to make it more complete?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.