我有一个单独的字段(不是一种形式),我想使用ajax发送他们的数据

时间:2014-11-30 07:32:11

标签: php jquery ajax

这是我的jquery代码:

var category= $('#category').val();

var week = $('#week').val();

var data = {'category': category , 'week': week , 'class': classification , 'pset': pset , 'text_question': question , 'question_keys': keywords};

        $.ajax({
            url: 'post_question.php',  //Server script to process data
            type: 'POST',
            xhr: function() {  // Custom XMLHttpRequest
                var myXhr = $.ajaxSettings.xhr();
                return myXhr;
            },
            //Ajax events
            success: function(output){
                         if(output == 'success')   
                         {
                            alert("success");                                
                         }
                         else
                         {  
                            alert("failed");
                         }
                     },
            error: function(){
                       alert("Error sending question to database!!"); 
                   },
            // Form data
            data: data,
            //Options to tell jQuery not to process data or worry about content-type.
            cache: false,
            contentType: true,
            processData: false
       });    

0 个答案:

没有答案