nickalchemist
nickalchemist

Reputation: 2241

AJAX call not working(Error 302) Magento

I am trying to make an AJAX call to PHP webservice in Magento. Here's my PHP code snippet.

    <?php 
$callbackUrl = "http://localhost/magento/webservices/NewCustomer1.php";
    //intiate oauth callback URL
    $temporaryCredentialsRequestUrl = "http://localhost/magento/oauth/initiate?oauth_callback=". urlencode($callbackUrl);
    $adminAuthorizationUrl = 'http://localhost/magento/admin/oauth_authorize';
    $accessTokenRequestUrl = 'http://localhost/magento/oauth/token';
    //Magento rest API URL
    $apiUrl = 'http://localhost/magento/api/rest';
    //Consumer key and secret
    $consumerKey = 's3xt7w8lwhfrrfzrfvwm3lrilkf66d5n';
    $consumerSecret = 'vr3eq1x899pz1cf4zzxjzx3q03t66r3n';
    //get customer attributes
    $firstname=$_POST['fname'];
    $lastname=$_POST['lname'];
    $email=$_POST['email'];
.......

Here's my jquery

 $('#btnSubmit').click(function(){
    console.log("Submit Clicked");
    var fName=$('#firstname').val();
    var lName=$('#lastname').val();
    var email=$('#email_address').val();
    var password=$('#password').val();
    var pass_conf=$('#confirmation').val();
    var dataString = 'fname='+ fName + '&lname=' + lName + '&email=' + email + '&password=' +password+ '&webid=1&groupid=1';
    /*http://localhost/magento/webservices/Newcustomer1.php?fname=siri&lname=s&[email protected]&password=password123&webid=1&groupid=1*/
    //your validation code
$.ajax({
        url: 'http://localhost/magento/webservices/Newcustomer1.php',
        type: 'POST',
        data: dataString, 
        success: function(data) {
            $('#message').html(data);
        }
    });
});

On submitting am getting 302 Found error. It works if I pass parameters in URL itself and change $_REQUEST to $_GET.

Thanks in advance.

Upvotes: 0

Views: 1533

Answers (1)

Max Doumit
Max Doumit

Reputation: 1115

Hey here is what you should do.

Give your form where the value that you need to send an ID ex :

<form id ="myfrom" >

Now in your ajax call do the following, instead of

data: dataString,

do

data : $('#myform').serialize() ,

Let me know if that fixes it. And in the PHP part i sugest that first you do

print_r($_POST);

just so you see how the data is passed.

Upvotes: 0

Related Questions