English 中文(简体)
javascript var returning object Object when should be returning an int or string
原标题:

I have two ajax functions and use the first one to pass some data to the second however when I look at the POST, I see that for the variable I am being sent I am getting object Object returned as the value of the variable and not what I was expecting either a string or an int. The javascript looks like this,

    $( .career_select .selectitems ).click(function(){
    var selectedCareer = $(this).attr( title );
    $.ajax({
        type:  POST ,
        url:  /roadmap/step_two ,
        data:  career_choice= +selectedCareer+"&ajax=true&submit_career=Next",
        success: function(html){
            $( .hfeed ).append(html);
            $( #grade_choice ).SelectCustomizer();
          }
    });
});

$( #grade_choice_options .selectitems ).live( click , function(selectedCareer){
    var selectedGrade = $( #grade_choice_customselect ).val();
    $.ajax({
        type:  POST ,
        url:  /roadmap/step_two ,
        data:  career_choice= +selectedCareer+ &grade= +selectedGrade+"&ajax=true&submit_grades=Next",
        success: function(html){
            window.location.replace("/roadmap/your_map");
        }
    });
});
最佳回答

In your second function selectedCareer is the event object passed into the method by jQuery, you likely want to use this to get which items was clicked, e.g. $(this).val() for inputs of $(this).text() to get an element s text.

Also you can pass data an an object, especially if it s a complex value (e.g. may contain a &), like this:

 data: { career_choice: $(this).val(),
         grade: selectedGrade,
         ajax:  true ,
         submit_grades:  Next  }
问题回答

暂无回答




相关问题
ajax login using httpRequest?

I am trying to develop my login script to give feedback to the user if the login is valid or not. Basically if it isn t correct a div box will show saying its wrong, if its correct it will show its ...

Virtual Tour using sketch up, ajax, flash technologies

I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...

How can i update div continuously

I have asp.net application where i have a div which showing the value from other site. The value of that site is changing continuously. I want that my div will automatically update in some interval ...

热门标签