0

How can I do this without the ajaxy goodness? I need to debug a troublesome php script. There isn't a form just an image that when clicked performs the following.

$.post("php/navTabs.php", { action: "deleteTab", theHTM: thehtm }, function(jdata) {
    alert("The tab was " + jdata.is_deleted);
}, "json");

Thanks again, Todd

maddogandnoriko
  • 980
  • 2
  • 13
  • 31

4 Answers4

2

I would change the $_POST variables in the php/navTabs.php to $_GET and access the script directly like

php/navTabs.php?name=value&name2=value2 etc

This way you don't have ajax in your way.

Sean H Jenkins
  • 1,770
  • 3
  • 21
  • 29
1

This method will allow you to use a flow very similar to $.post() as it happens transparently to the user and enables a callback function:

<img />
<iframe id="workFrame" style="display: none"></iframe>
<form action="php/navTabs.php" target="workFrame" method="post" style="display: none">
<input type=hidden id="hidden-1">
<input type=hidden id="hidden-2">
</form>

<script>
$('#hidden-1').val('some value to send to the server');
$('#hidden-2').val('some OTHER value to send to the server');
$('img').on('click', function () {
    $('form').trigger('submit');
});
</script>

This uses a form with hidden inputs (so this can be transparent to the user). You can set the value of the hidden inputs using JavaScript and then programmatically submit the form to a hidden iframe.

Another feature of this method is that you can bind to the load event for the iframe and have a callback function just like in $.post():

$('#workFrame').on('load', function () {
    var response = $(this).contents().filter('body');
    //if you output JSON in your PHP script you could parse this as JSON and do work
});

UPDATE

If all you want to do is see the output from your PHP script then you can use your Developer Tools (FireBug, etc.) to view the response. You can also log the response in your AJAX callback:

$.post("php/navTabs.php", { action: "deleteTab", theHTM: thehtm }, function(jdata) {
    alert("The tab was " + jdata.is_deleted);
    console.log(jdata);
}, "json");

If you are not currently using some Dev. Tools with a console, I highly recommend checking FireBug out, it will save you amazing amounts of time debugging code.

Jasper
  • 75,717
  • 14
  • 151
  • 146
0

Short answer: you can't with Javascript.

Long answer:

If you want to avoid using AJAX, you have two options:

1) Make the image part of a form and submit hidden inputs upon clicking the button.

   <form method="form.php" action="post">
        <input type="hidden" name="action" value="delete"/>
        ...rest of form...
   </form>

2) Make the image a link with the inputs tacked onto the URL. Like:

   form.php?action=delete

Not sure why you'd want to avoid using AJAX, though.

Jemaclus
  • 2,356
  • 1
  • 15
  • 13
  • Of course if can be done, you access the script directly. The PHP file exists? AJAX doesn't magic parsed content out of no where. – Sean H Jenkins Dec 02 '11 at 18:22
  • Um, yeah, but you can't use jQuery/Javascript to send data to the PHP file without using AJAX. You can make the image a link and send the data along in the URL like your answer says, or you can change it to a form, but you can't send that data via jQuery/Javascript without using AJAX, as far as I'm aware. – Jemaclus Dec 02 '11 at 18:24
  • In the end I do not want to bypass ajax, but I have a php script that is not acting correctly and i need to put some var_dumps and echos to see WTF is going on. – maddogandnoriko Dec 02 '11 at 18:25
  • In that case, if you use Firebug, you can look at the AJAX response in that. Checkout Firebug's page to see what I'm talking about. Alternately, you can put console.log(jdata) where that alert is to see what the response is from the PHP file. We'd have to see the PHP file to give you more support about what's going wrong. – Jemaclus Dec 02 '11 at 18:27
  • @maddogandnoriko You *can* do this with JavaScript. You can build the form dynamically, populate it dynamically, and send it dynamically. You can even create a callback function (see my answer). – Jasper Dec 02 '11 at 22:06
  • down-vote for the first statement: `you can't with Javascript`, that is just false. – Jasper Dec 29 '11 at 20:40
-1

Let's Try...

        var latitude = 51.509865 ;
        var longitude =  -0.118092;

        document.cookie = "latitude = " + latitude
       document.cookie = "longitude = " + longitude

PHP Code:-

     $lat_visitor  = $_COOKIE['latitude'];

    $long_visitor = $_COOKIE['longitude'];
Devsaiful
  • 147
  • 4