0
我想在Magento中對PHP webservice進行AJAX調用。這是我的PHP代碼片段。AJAX調用不工作(錯誤302)Magento
<?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'];
.......
這裏是我的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);
}
});
});
在提交我得到302發現的錯誤。如果我在URL本身傳遞參數並將$ _REQUEST更改爲$ _GET,它將起作用。
在此先感謝。
302如果請求的URL使用重定向邀請進行響應,則會發生302。我的猜測是,當您嘗試進行身份驗證時發生... –