1

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

1
  • You could use cURL to post from the command line. Commented Dec 2, 2011 at 18:19

4 Answers 4

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.

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

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.

6 Comments

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.
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.
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.
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.
@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).
|
-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'];

1 Comment

Why use cookies that most people hate ?!

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.