tags:

views:

36

answers:

2

Hello

I have this code:

<script type="text/javascript">
    var loader = "#loader";

    $(function() {
        $("#selUsers").change(function() {
            if ($(this).val() != "") {
                $(loader).show();

                $.ajax({
                    type: "POST",
                    url: "",
                    data: {
                        userID: $(this).val()
                    },
                    success: function(msg) {

                        $("#Firstname").val(msg[0].Firstname || "");
                        $("#Surname").val(msg[0].Surname || "");
                        $("#Email").val(msg[0].Email || "");
                        $("#Phone").val(msg[0].Phone || "");
                        $("#Mobile").val(msg[0].Mobile || "");
                        $("#Address").val(msg[0].Address || "");
                        $("#Zipcode").val(msg[0].Zipcode || "");
                        $("#City").val(msg[0].City || "");
                        $(loader).hide();
                    },
                    error: function() {
                        $(loader).hide()
                    }
                });
            } else {
                $(":input[type=text]").val("");
                $("#BookingNotes").val("");
            }

        });
    });
</script>

And I have included these:

<script src="/Scripts/jquery-1.4.2.min.js" type="text/javascript"></script>
<script src="/Scripts/jquery-ui-1.8.custom.min.js" type="text/javascript"></script>

And I get invalid argument.... can't see which row of those, since row 127 is a html-tag only..

As I recall this worked before, maybe I have included wrong javascript?

You guys have any clue what might be wrong?

/M

+1  A: 
data: { userID : $(this).val() }, // $(this) refers to $ object...

should be like

$("#selUsers").change(function() {
  var userID = $(this).val();
  if($(this).val() != "")
        {
            $(loader).show();
         //...............
         //..............
              data: { userID : userID }, 
Reigel
A: 

You could also try declaring the data object before you pass it to the ajax function. In this way, the ajax will just receive an already complete data object. This increases readability, but that's just my opinion.

//define the object and create the needed nodes before the ajax call
var data = {};
data.userID = $(this).val();

$.ajax({
    type: "POST",
    url: "",
    data: data, //just pass the whole already complete object
    success: function(msg) {
    and so on..
Stefan Konno