Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- jQuery(document).ready(function($){
- // Create common ajax method by JQuery
- $.ajaxExec = function(config) {
- // The default value of the argument
- config = jQuery.extend({
- data: "",
- success: function() {}
- },config);
- // Send ajax request
- $.ajax({
- type: "GET",
- url: config.url,
- data: config.data,
- timeout: 60000,
- async: true,
- cache: false,
- contentType: "application/json; charset=utf-8",
- xhrFields: {
- withCredentials: true
- },
- crossDomain: true,
- // When success response
- success: function(obj) {
- // Call success method
- config.success(obj);
- },
- // When error response
- error: function(XMLHttpRequest, textStatus, errorThrown) {
- // Show error message
- },
- complete: function(XMLHttpRequest, textStatus) {
- }
- });
- };
- //$.fn.apiLogin = function(){
- var user = $("#userName").val();
- var pass = $("#userPass").val();
- // Call login method
- // var submitUrl = 'http://api.partsdb.com.au/v1.0/Authentication/Login?UserName='+ user +'&Password='+pass;
- var submitUrl = "http://api.partsdb.com.au/v1.0/Authentication/Login?UserName=partsapi@cqfis.com.au&Password=CjdB22fDc";
- $.ajaxExec({
- url: submitUrl,
- success: function(data) {
- if (data.Code != '0000') {
- console.log('User name or password is invalid');
- return;
- } else {
- loginFlag = '1';
- // Call method after login successfuly
- $.fn.GetAllProductsSubscribed();
- }
- }
- });
- //}
- $.fn.GetAllProductsSubscribed = function(){
- var BrandID = "10231";
- var PageNum = "1";
- var PageSize = "2";
- var getDataUrl = "http://api.partsdb.com.au/v1.0/Product/ProductsSubscribed?BrandID=" + BrandID + "&PageNum=" + PageNum + "&PageSize=" + PageSize;
- var ret = "";
- $.ajaxExec({
- url: getDataUrl,
- success: function(prod) {
- // Process success JSON data here
- ret = JSON.stringify(prod);
- $.fn.ajaxPhp(prod);
- }
- });
- }
- $.fn.ajaxPhp = function(ret){
- $.each( ret, function( keyRet, valueRet ) {
- $.each( valueRet, function( keyAttr, valueAttr ) {
- console.log( keyAttr + ": " + JSON.stringify(valueAttr) );
- });
- });
- }
- $('#test_ajax').click(function(){
- var baseUrl = document.location.origin;
- var sku = $("#sku").val();
- $.ajax({
- url: baseUrl+"/magento-test/seven-magecustom/index/insertProduct",
- type: "POST",
- data: {pname:sku},
- success: function(data) {
- alert(data);
- }
- });
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement