Paul
Paul

Reputation: 11746

Can I load just a portion of a page without java script?

I'm using PHP for my server side language and have a form that returns results. I'm currently using jquery to retrieve the results and update a portion of the page. Can this be done without jquery? If so are there any good examples?

My current jquery code looks like this:

$.post("search_basic_results.php", $("#profile_form_id").serialize(),
    function(data) {    
        $('#search_results').html(data);
    });
});

I'm trying to find a java script free alternative but I'm afraid I'll need to reload the entire page again.

Upvotes: 1

Views: 117

Answers (4)

Shiplu Mokaddim
Shiplu Mokaddim

Reputation: 57650

Without Javascript its not possible.

Here is the old school Javascript code.

if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("POST","search_basic_results.php",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;

Upvotes: 2

Uboonto
Uboonto

Reputation: 69

What's the problem in reloading the page?

if (count($_POST) == 0)
{
  // var initialisation
  $input_one = ''; 
  $input_two = '';
  // result wont be displaied
  $display_search = false;
}
else
{
  // this bit keeps track of the input fields
  $input_one = $_POST['input_one'];
  $input_two = $_POST['input_two'];
  // result will be displayed
  $display_search = true;
  // do some stuff that search_basic_results.php would do
}
?>
<form action="" method="post">
  <input name="input_one" type="text" value="<?=$input_one?>"/>
  <input name="input_two" type="text" value="<?=$input_two?>"/>
</form>
<? if ($display search == true): ?>
<!-- display stuff you want to display here /  $('#search_results').html(data); equivalent -->
<? endif ?>

Upvotes: 1

Quentin
Quentin

Reputation: 943591

Can this be done without jquery?

Yes. jQuery is just a library. It provides helper functions to do things with less code and to iron over differences between browsers.

There are other libraries to choose from (I'm fond of YUI3), and the source code for jQuery is available so you can see what it is doing behind the scenes if you want to.

I'm trying to find a JavaScript free alternative

You can't edit a document in the browser without client side programming. JavaScript is the only widely supported language for manipulating the browser DOM.

You could use an iframe though.

Upvotes: 3

Darin Dimitrov
Darin Dimitrov

Reputation: 1038890

Can this be done without jquery?

Sure, you could use plain old javascript AJAX. You will have to write bit of a code. But why would you do this, when you have a cross browser working alternative with jQuery?

As far as manipulating the DOM without javascript is concerned, this cannot be done without reloading the entire page.

Upvotes: 1

Related Questions