0

I have code as below:

jQuery.ajax({
    url: '/Control/delete',
    type: 'GET',
    contentType: 'application/json',
    success: function (bool) {
        if (bool == "deleted") {
            alert('record deleted');
            $(".row" + currentId).hide('slow');
        }
        else {
            alert('not deleted ');
        }
    }
});

Aay for example I need to send file_id (?file_id=12) paramater using GET, how can i do so?

6 Answers 6

3

Use the data parameter

jQuery.ajax({
  url: '/Control/delete',
  type: 'GET',
  contentType: 'application/json',
  data: {file_id: 12}
  success: function (bool){
  if(bool == "deleted"){
    alert('record deleted');
    $(".row"+currentId).hide('slow');
  }
  else{
    alert('not deleted ');                  
  }
 }
});

Also not that data can be also a query string like:

data: "file_id=12&foo=bar"

In case if its not a query string, jQuery will automatically convert it to query string.

Data to be sent to the server. It is converted to a query string, if not already a string.

jQuery.ajax docs

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

Comments

2

Use data option:

jQuery.ajax({
  type: 'GET',
  data: {file_id : 12},
  ......
});

http://api.jquery.com/jQuery.ajax/

3 Comments

The actual GET method data: "file_id=12&someother=othervalue"
Ok then how do you write a POST method
@ubercooluk: read the docs :) and what you say is another way of doing it
1

Use this replace url with /url/delete?file_id=12

jQuery.ajax({
      url: '/Control/delete?file_id=12',
      type: 'GET',
      contentType: 'application/json',
      success: function (bool){
      if(bool == "deleted"){
        alert('record deleted');
        $(".row"+currentId).hide('slow');
      }
      else{
        alert('not deleted ');                  
      }
     }
    });

Comments

0

Just add it to URL:

url: '/Control/delete?file_id=12',

Comments

0

Use the data option of the ajax call and pass it an object with your key value pairs.

Comments

0
//POST METHOD

$.ajax({
  type: 'POST',
  data: {file_id : 12},
  ......
});

//GET METHOD

$.ajax({
  type: 'GET',
  data: "file_id=12&someother=othervalue",
  ......
});

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.