basit jquery mysql alınamayacak

3 Cevap php

Ben MySQL ile jQuery kullanmak çalışıyorum ve böyle bir şey yazdı:

<html>

<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script>
function example_ajax_request() {
  $('#example-placeholder').html('<p>Loading results ... <img src="ajax-loader.gif"  /></p>');
  $('#example-placeholder').load("loadres.php");
}
</script>
</head>
<body>
<div id="query">
<select name="show"  id="box" >

 <option value="0">Select A Test</option>
 <option value="All">--All--</option>
 <option value="M1">Model1</option>
    </select>
<input type="button" onclick="example_ajax_request()" value="Click Me!" />
</div>
<div id="example-placeholder">
  <p>Placeholding text</p>
</div></body>
</html>

Basically I want to pass parameters to the loadres.php file. But unable to figure out the exact way to do. Any help is appreciated.

Teşekkürler.

3 Cevap

$('#example-placeholder').load("loadres.php?show=" + $('#box option:selected').val());

Bu açılan listeden seçilen değeri almak ve loadres.php sayfasında erişebileceğiniz bir QueryString parametresi olarak URL bunu eklemek için jquery kullanmak olacaktır.

Sen jQuery $. Ajax () yöntemini kullanmanız gerekir. Eğer url veri geçmek ve sonunda bir geri olabilir.

$.ajax({
  url: 'loader.php',
  data: 'somedata',
  type: 'GET',
  success: function(data){
    $('#example-placeholder').text(data);
  }
});

Bu hile yapacak. Bu yöntem, aynı zamanda çok daha fazla esneklik sağlar. Bu tür hata fonksiyonları ve tam fonksiyonları gibi farklı işlevlere sahip olabilir.

saif-bechan's Eğer yazı ve veri ile ajax kullanabilirsiniz yayınlamak için benzer birden fazla parametre iletmek için bir nesneyi tutabilir

    $.ajax({
        type:"POST",
        url: loadres.php,
        data: {
              foo:'bar',
              selected:$('#selector').val()
        },
        dataType: 'json',
        error: function(data) {
                   //error code here
        },
        success: function(data) {
                      //success code here
        }
    });

Ben de o html jquery bağlamda tıklama olayı değil koymak için daha iyi olduğunu unutmayın olacaktır

böylece script yerde kullanın

 $('#button_id').click(function(){
       //call to ajax
 };