0

I am trying to get some data from a web service:

 $.ajax({
        type: 'POST',
        contentType: 'application/json;', 
        url: 'http://***.asmx/GetJSONString',
        data: "Select * from con",
        crossDomain:true,
        dataType: 'json',
        success: function(response) { 
            alert(response); 
        },
        error: function(XMLHttpRequest, textStatus, error) {
            alert("Error");
        }            
    });

where/how i have to write sql? in data?

Mikelon85
  • 432
  • 1
  • 13
  • 30
  • It's not secure way to do queries like that. You should send some variables to file and then do your sql – vinculis May 24 '12 at 10:12

2 Answers2

1

Yes but you forgot to pass a POST param name

It can be object:

data: { sqlQuery: "Select * from con" }

Or string:

data: "sqlQuery=Select * from con"

Now in your server side you will get POST variable sqlQuery with your SQL string.

Read more about $.ajax.

antyrat
  • 27,479
  • 9
  • 75
  • 76
1

you have to pass this paramater as json string .. you can do this as

d={ sqlQuery: "Select * from con" }
$.ajax({
    type: 'POST',
    contentType: 'application/json;', 
    url: 'your url',
    data: JSON.stringify(d),
    crossDomain:true,
    dataType: 'json',
    success: function(response) { 
        alert(response); 
    },
    error: function(XMLHttpRequest, textStatus, error) {
        alert("Error");
    }            
});
gsagrawal
  • 2,900
  • 4
  • 27
  • 27