0

I want to use query string in my URL using Jquery ajax below are my codes :

function load_content()
    {
        var msg=$(".message_box:last").attr("id");
        var baseurl = $("#baseurl").val();
        var ids = msg.split('-');
        var url = baseurl+"shops/load_allshops/"+{/literal}{php} if($_GET['country']!=''){ echo "?country=".$_GET['country']."&state=".$_GET['country']."&city=".$_GET['city']."&area=".$_GET['area'];}{/php}{literal};

        $.post(url, {start: ids[0], limit: ids[1]},
        function(data){
            if (data != "") {
                $(".message_box:last").after(data);
            }
            $('.last_msg_loader').fadeOut();
            });
        };

Error :

 SyntaxError: syntax error


...url = baseurl+"shops/load_allshops/"+?country=India&state=India&city=Madurai&are...

pointing near +?country

Please let me know the error

2
  • ?country=India&state=India&city=Madurai&are... this part should be a string. Commented Dec 30, 2013 at 7:33
  • "shops/load_allshops/"+?country must be "shops/load_allshops/"+"?country. Check strings concated to the baseurl Commented Dec 30, 2013 at 7:34

3 Answers 3

2

Eventually, a POST request can include query string as well, however normally it doesn't.

A standard HTML form with a POST action will not include query string, therefore either you need to change your action type to GET or send data through hidden fields.

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

Comments

0

your url must be like this...

  ...url = baseurl+"shops/load_allshops/?country="+ India + "&state="+India+"&city="+ Madurai+"&are..."

Comments

0

Try this with arrays:

function load_content(){
//Your vars
var data=new Array();

//Just do some vars to get their value...
data[0]=$('#country').val();
data[1]=$('#city').val();
data[2]=$('#area').val();

//Forget to split or vars for url...

var data={"data":data};
$.post('getdata.php',data,function(data){
//And show php answer here...
alert(data);
});
return false;

}

example of getdata.php

<?php
$data=$_POST['data'];
echo "Country: $data[0]";
echo "City: $data[1]";
echo "Area: $data[2]";
?>

Arrays are useful. Have fun!

Comments

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.