Michael Lam
Michael Lam

Reputation: 69

Ajax post not sending data out

var dataString = 'edulevel='+ edulevel
                        + '&course=' + course
                        + '&financerelated=' + financerelated     
                        + '&occupation=' + occupation
                        + '&joblevel=' + joblevel
                        + '&income=' + income
                        + '&bankname=' + bankname
                        + '&acctype=' + acctype
                        + '&accno=' + accno;


        //ajax
        $.ajax({
            type:"POST",
            url: "process/veriamateur.php",
            data: dataString,
            success: success(),
            error:function(jqXHR, textStatus, errorThrown){
                                   alert("Error type" + textStatus + "occured, with value " + errorThrown);
                               }

            });

I have checked and made sure that dataString was sending out correct stuff, however, the ajax was just not sending out any data, no error whatsoever. Even when I changed the url to an invalid one it still went to my success function.

Upvotes: 0

Views: 235

Answers (2)

Pankaj Khairnar
Pankaj Khairnar

Reputation: 3118

I have made some changes and now this is working your callback function was success() and jQuery was trying to find the function, either you can write your function at same place or you can write a stand alone function and assign it to sucess:, if you are still getting problem try to change your url, if your current files location is /files/file.php then your veriamateur.php must be /files/process/veriamateur.php

var dataString = 'edulevel='+ edulevel
                        + '&course=' + course
                        + '&financerelated=' + financerelated     
                        + '&occupation=' + occupation
                        + '&joblevel=' + joblevel
                        + '&income=' + income
                        + '&bankname=' + bankname
                        + '&acctype=' + acctype
                        + '&accno=' + accno;


        //ajax
        $.ajax({
            type:"POST",
            url: "process/veriamateur.php",
            data: dataString,
            success: function(){ alert('success');},
            error:function(jqXHR, textStatus, errorThrown){
                                   alert("Error type" + textStatus + "occured, with value " + errorThrown);
                               }

            });

Upvotes: 0

macool
macool

Reputation: 658

You should pass data as an object instead of a string when you are sending via POST

Example:

data = {
  'edulevel': edulevel,
  'course': course
  (.....)
};

Upvotes: 1

Related Questions