Sunday, 15 July 2012

Cannot send jQuery ajax() request to php -



Cannot send jQuery ajax() request to php -

i have problem in using ajax() function. have html file form , have segment of javascript code:

<script> $(document).ready(function(){ $("form").submit(function(){ var url = "xxx.php/"; var param = $("#streetinput").serialize() + "&"; param += $("#cityinput").serialize() + "&"; param += $("#stateinput").serialize(); htmlobj = $.ajax({ url: url, data: param, type: 'get', datatype: 'json', success: function(output) { // parse info here }, error: function() { } }); }); }); </script>

i want build url pointing specified php file method. however, don't know how retrieve parameters sent through url in xxx.php file. don't know how debug. type

<?php echo $_get("streetinput"); echo $_get("cityinput"); ...... $xml = simplexml_load_file($url); ?>

but didn't work. can help me out? want give 3 parameters through url xxx.php, print elements

in xxx.php file, build url api request , xml file back. , want convert $xml file json format , homecoming html file.

change js code to:

<script> $(document).ready(function(){ $("form").submit(function(){ var url = "xxx.php"; var param = $("#streetinput").serialize() + "&"; param += $("#cityinput").serialize() + "&"; param += $("#stateinput").serialize(); $.ajax({url: url, data: param, type: 'get'}); }); }); </script>

or, if have these fields in form, utilize this:

<script> $(document).ready(function(){ $("form").submit(function(){ var url = "xxx.php"; var param = $(this).serializearray(); //<- or, .serialize() can used $.ajax({url: url, data: param, type: 'get'}); }); }); </script>

php jquery

No comments:

Post a Comment