2

I have following Ajax Success method :

 success: function(data, el){

    var parent = el.find(".jFiler-jProgressBar").parent();

    el.find(".jFiler-jProgressBar").fadeOut("slow", function(){
    $("<div class=\"jFiler-item-others text-success\"><i class=\"icon-jfi-check-circle\"></i> Success <b class=\"text-danger\">&nbsp;&nbsp;&nbsp;<a href=\"#delete_upload_image\">Delete</a></b></div>").hide().appendTo(parent).fadeIn("slow");    
    });

    console.log(data);        
 },

In this success method you see that I have a link which is :

<a href=\"#delete_upload_image\">Delete</a>

and

console.log(data)

This console.log(data) is returning following String :

mpic_list_573ecaafae8220.41741946 |76|40

Now I want call a php page e.g : delete_upload_image.php after click on this link <a href=\"#delete_upload_image\">Delete</a> with a string mpic_list_573ecaafae8220.41741946 and 76 and 40

I mean :

In delete_upload_image.php page I can get 3 string which is passed when I click on the delete link. `

5
  • 1
    Can't you just make another ajax request? or a simple GET request to example.com/delete_upload_image.php?thestring= mpic_list_573ecaafae8220.41741946&firstint=76&secondint=40 ? Commented May 20, 2016 at 8:53
  • How to get the sting and pass to the Link from console.log() ? Commented May 20, 2016 at 8:55
  • you can't pass something from console.log() just use data that variable contains the string you need Commented May 20, 2016 at 8:56
  • Your want to make a second ajax request for deleting an image ? or just a link GET ? Commented May 20, 2016 at 8:59
  • I want to call second ajax request to deleting an image which image name is : mpic_list_573ecaafae8220.41741946 and there are 2 id which value is : 76 and 40. Commented May 20, 2016 at 9:00

4 Answers 4

0

Catch your parameters in your data using split method :

var stringParam = data.split('|')[0];
var int1Param= data.split('|')[1];
var int2Param= data.split('|')[2];

then put your parameters inside your link :

$("<div class=\"jFiler-item-others text-success\"><i class=\"icon-jfi-check-circle\"></i> Success <b class=\"text-danger\">&nbsp;&nbsp;&nbsp;<a href=\"delete_upload_image.php?string="+ stringParam +"&int=" + int1Param + "&secondint=" + int2Param + "\">Delete</a></b></div>").hide().appendTo(parent).fadeIn("slow");
Sign up to request clarification or add additional context in comments.

Comments

0

You must either bind the click to a function where you send the user to the desired page or directly make a link in the button.

First, if you want to send the differents params separately, you must split them.

var params = data.split('|');

And then use it as you want, for example bind the click method to the new link to create a new ajax call.

$('#delete_upload_image').on('click', function() {
    var params = data.split('|');
    var url = "delete_upload_image.php?param1=" + params[0] +"&param2=" + params[1] + "&param3=" + params[2];

    // Make AJAX call as you want to url
    $.get(url);

});

2 Comments

I used your given code but why It's not calling Ajax ?
One question : is there any other way to securely pass those params value ?
0
  1. you must put your data in your link tag:
<a href=\"#delete_upload_image\" data-params='" + data + "'>Delete</a>
  1. then you can send delete requests to "delete_upload_image.php" by below codes:
$(function(){
  $('body').on('click', '[href=#delete_upload_image]', function() {
    var params = $(this).data('params').split('|');
    var url = "delete_upload_image.php?param1=" + params[0] +"&param2=" + params[1] + "&param3=" + params[2];

    // Make AJAX call as you want to url
    $.get(url);
  });      
});

Comments

0

now I understand what is your problem;

You want to get the parameters from console.log.

but you can not get the console.log value directly.

What you can do is:

  1. hook the console.log function so that you store when it logs by this code:
var store = '';
var oldf = console.log;
console.log = function(){
   store = JSON.stringify(arguments);
   oldf.apply(console, arguments);
}
  1. use below function to get parameters from console_store variable and delete image:
function delete_image()
{
  var params = store.split('|'),
  queryString = $.param({param0:params[0], param1:params[1], param2:params[2]}),
  url = "delete_upload_image.php?" + queryString;
  $.get(url);
}
  1. call the function on link click:
$('body').on('click', '[href=#delete_upload_image]', delete_image);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.