Forums

Ajax call to admin-ajax.php for certain users results in Login Screen (1 post)

  1. cwhittl
    Member
    Posted 4 months ago #

    We have a plugin that's calling the backend and works for 90% of our users but a couple get the ajax result a login screen. Any ideas?

    function shoppertunity_user_action_ajax_call(id, data) {
    	var missing = false;
    	if(id) {
    
    		var listitems = jQuery('#' + id).find('.question').get();
    		var questions = {};
    		if(listitems) {
    			jQuery.each(listitems, function(idx, itm) {
    				if(missing) {
    					return;
    				}
    				var my_id = jQuery(itm).attr("id");
    				my_id = my_id.replace("_" + id, "");
    				var val = jQuery(itm).val();
    				val = jQuery.trim(val);
    				if(val == "") {
    					alert("You're missing something.. Look it over before you continue");
    					missing = true;
    				}
    				questions[my_id] = val;
    			});
    			data.answers = questions;
    		}
    		comment = jQuery('#' + id).find('.comment');
    		if(comment) {
    			data.comment = comment.val();
    		}
    	}
    	if(missing) {
    		return;
    	}
    	//alert(JSON.stringify(data));
    	//return;
    	// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
    	jQuery.post(ajaxurl, data, function(response) {
    		try {
    			var json_obj = JSON.parse(response);
    			if(json_obj.success == 1) {
    				//alert(json_obj.message);
    				if(top != self) {
    					top.location.reload();
    				} else {
    					window.location.reload();
    				}
    			} else {
    				alert("There was an error with your last action - (" + json_obj.message + ")");
    				alert(response);
    			}
    		} catch(err) {
    			alert('There was and unknown error(' + err + ')');
    			alert(response);
    		}
    	});
    }

Reply

You must log in to post.

About this Topic

Tags