0

I have a question,I'd like to send data using method post using ajax call,so I do like that:

       jQuery.noConflict();

        jQuery(document).ready(function () {
        $("input#submit").click(function(){
            $.ajax({
                type: "POST",
                url: "ajax?uid="+<?php echo   $sf_user->getGuardUser()->getId() ?>+"fid="+<?php echo $user->getId() ?>+"fn="+<?php echo $user->getfirstName() ?> +"ln="+<?php echo $user->getlastName() ?>, // 
                data: $('form.contact').serialize(),
                success: function(msg){
                    $("#thanks").html(msg)
                    $("#form-content").modal('hide');   
                },
                error: function(){
                    alert("Something is wrong!");
                }
            });
        });
    });
</script>

But It seems not working for me, i get this strange error :

ReferenceError: Jean is not defined url: "ajax?uid="+1+"fid="+13+"fn="+Jean +"ln="+paul, //

Very strange because when I remove fn and ln and I keep just the number value it works very well?

Nabil El
  • 27
  • 8

2 Answers2

1

You need to enclose the string values within ''.. Values like Jean is a string value, so it need to be enclosed within '' else it will be considered as a variable and during execution time when it is looked up, the js engine will not find it causing the said error.

url: "ajax?uid="+<?php echo   $sf_user->getGuardUser()->getId() ?>+"fid="+'<?php echo $user->getId() ?>'+"fn="+'<?php echo $user->getfirstName() ?>' +"ln="+'<?php echo $user->getlastName() ?>', // 
Arun P Johny
  • 384,651
  • 66
  • 527
  • 531
0

jQuery.ready() is an event which fires when page is loaded.

Thus only code that accesses the DOM should be in ready handler. If it's a plugin, it shouldn't be in the ready event.

Thus don't put your ajax call within ready function.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
myk.
  • 323
  • 1
  • 5