cómo pasar el valor <entrada> a php usando carga ajax

I am trying to pass a value of an input item to php when loading the php file using ajax_load. this is that I have so far but it's not working.

html and jquery:

        <button class="grey">Test Settings</button></td>

    <td><div class="font-size-15 color-semi-black" id="result"></div></td>
<input type="hidden" name="control" value="1"/>

<!--Test Settings-->
            cache: false
        var ajax_load = "<img src='images/loaders/small-loader.gif' alt='loading...' />";
        var value = $("input[name='control']").val();
        //  load() functions
        var loadUrl = "demo/test_settings.php?val=" + value;
        $("button").click(function() {



if ($val == '1'){

//process code here. 


It's not passing the value of the input. any suggestions?

preguntado el 28 de mayo de 14 a las 12:05

No need to. He can capture it trough query string -

there are numbers of ajax jquery tutorials. try to search in Google -

it would be very helpful if you could just post the actual content of your test_settings.php file too. Otherwise, we assume that your $val is set as: $val = $_GET['val']. -

thank you all for commenting. the reason I did not post the content of the php is because it is about 200 lines of coding which is not related to this. but same suggestion as below works great. -

3 Respuestas

your request is going with GET como esto:-


so you need to get your values by $_GET on test_settings.php como

if ($_GET['val'] == '1'){

contestado el 28 de mayo de 14 a las 13:05

thank you for your suggestion. had a few problem with ?val=1&_=1401278450924 but I changed to .php?val=1"; and that works - user3620142

En su $.load pass data to it as a parameter.

    $("#result").html(ajax_load).load(loadUrl , {
         val : ...

En su archivo php:

if (isset($_REQUEST["val"]) && $_REQUEST["val"] == 1) {

If you pass an object, it is passed as POST, otherwise it is passed as GET.

contestado el 28 de mayo de 14 a las 13:05

Y, qué piensas load() ¿lo hace? - aspirina

Edited it. Somehow forgot you can actually pass parameters to load, my bad. - Mareckmareck

This is not the problem, he is already passing the value in the query string. The problem is how he retrieves it in php - Steve

Yeah, but passing the values like that is a better way to deal with it. - Mareckmareck

guys, I was able to use suggestions from here and do this. test_connection.php?val=1"; php: ($_GET['val'] == '1'){ and it works fine - user3620142

if (count($_GET) && $_GET['val'] == '1'){

contestado el 28 de mayo de 14 a las 13:05

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.