admin管理员组

文章数量:1023018

I work in advertising. I am using the FB graph API to 'DELETE' ad assignments from the platform for a client using the HTTP DELETE method.

My requests are in the format:

.5/{{NODE_ID}}/{{EDGE_NAME}}?field_ids=['123456']

I normally use the graph explorer tool () to acplish such a task, but the client has provided over 8000 assignment to delete so doing it manually one by one would be tough.

How can I invoke an HTTP DELETE method using JavaScript? I want to use a for loop like this:

var node_ids = ["123","456","789"];
var field_ids = ["abc","def","ghi"];

for (i = 0; i < node_ids.length < i++){

// MAKE DELETE REQUEST to ".5/" + node_ids[i] + "/{{EDGE_NAME}}/?field_ids=['" + field_ids[i] + "']";

}

I saw a code like this online that I thought might be applicable, but I don't know how it works...

$.ajax({
    url: '/script.cgi',
    type: 'DELETE',
    success: function(result) {
        console.log(result)
    }
});

It looks like jquery but I guess it must be ajax? Does ajax need a library to be referenced like jquery does? Is it as simple as putting this function inside my for-loop and passing the URL I'm building inside the for loop to the 'url' field in the ajax call...?

What is the best function to pass to the 'success' parameter here so I know my request was successful? Is it possible to return the response from the delete request i.e. success:true if it works?

The more explicit you can be, the better!

Do you foresee any issues with me looping through 8000 entries across two arrays (one contains the node ID / object I am editing, and one contains a field related to the edge I'm accessing which will delete aka 'remove' the assignment from the node I am accessing...?

Thanks!

I work in advertising. I am using the FB graph API to 'DELETE' ad assignments from the platform for a client using the HTTP DELETE method.

My requests are in the format:

https://graph.facebook./v2.5/{{NODE_ID}}/{{EDGE_NAME}}?field_ids=['123456']

I normally use the graph explorer tool (https://developers.facebook./tools/explorer) to acplish such a task, but the client has provided over 8000 assignment to delete so doing it manually one by one would be tough.

How can I invoke an HTTP DELETE method using JavaScript? I want to use a for loop like this:

var node_ids = ["123","456","789"];
var field_ids = ["abc","def","ghi"];

for (i = 0; i < node_ids.length < i++){

// MAKE DELETE REQUEST to "https://graph.facebook./v2.5/" + node_ids[i] + "/{{EDGE_NAME}}/?field_ids=['" + field_ids[i] + "']";

}

I saw a code like this online that I thought might be applicable, but I don't know how it works...

$.ajax({
    url: '/script.cgi',
    type: 'DELETE',
    success: function(result) {
        console.log(result)
    }
});

It looks like jquery but I guess it must be ajax? Does ajax need a library to be referenced like jquery does? Is it as simple as putting this function inside my for-loop and passing the URL I'm building inside the for loop to the 'url' field in the ajax call...?

What is the best function to pass to the 'success' parameter here so I know my request was successful? Is it possible to return the response from the delete request i.e. success:true if it works?

The more explicit you can be, the better!

Do you foresee any issues with me looping through 8000 entries across two arrays (one contains the node ID / object I am editing, and one contains a field related to the edge I'm accessing which will delete aka 'remove' the assignment from the node I am accessing...?

Thanks!

Share Improve this question edited Jan 19, 2016 at 23:48 Kamui asked Jan 19, 2016 at 23:46 KamuiKamui 7991 gold badge9 silver badges17 bronze badges 2
  • 1 $.ajax is jQuery. api.jquery./jquery.ajax – user247702 Commented Jan 19, 2016 at 23:48
  • Please read a bit more online, run through a few tutorials about jQuery and ajax. Right now you have way too many questions here and it is therefore overly broad. Have a look at How to Ask for information. – Heretic Monkey Commented Jan 19, 2016 at 23:49
Add a ment  | 

1 Answer 1

Reset to default 4

It looks like jquery but I guess it must be ajax?

Ajax is a term used to mean "Making an HTTP request, using JavaScript, from a webpage, without leaving the page". There is no way to make a DELETE request from a webpage without using Ajax.

The example code you have uses the jQuery library to achieve it.

Does ajax need a library to be referenced like jquery does?

You need some means to make the HTTP request. JavaScript has nothing for that built in, but most host environments provide at least one mechanism for it. In the case of a web browser, the standard mechanism is XMLHttpRequest. jQuery's Ajax function is a wrapper around that (usually, there are some exceptions, notably when a JSONP request is made).

Is it as simple as putting this function inside my for-loop and passing the URL I'm building inside the for loop to the 'url' field in the ajax call...?

Yes.

What is the best function to pass to the 'success' parameter here so I know my request was successful?

That depends on what you mean by "know" and "successful".

The code you have will log the response to the console if a successful HTTP status was achieved. If you want to be informed by some other mechanism then you'll need to be more more specific.

If the server doesn't give any content in the response or (in the unlikely event of) it doesn't give a sane HTTP status code, then you might need something else.

Is it possible to return the response from the delete request i.e. success:true if it works?

No. Ajax is asynchronous.

I work in advertising. I am using the FB graph API to 'DELETE' ad assignments from the platform for a client using the HTTP DELETE method.

My requests are in the format:

.5/{{NODE_ID}}/{{EDGE_NAME}}?field_ids=['123456']

I normally use the graph explorer tool () to acplish such a task, but the client has provided over 8000 assignment to delete so doing it manually one by one would be tough.

How can I invoke an HTTP DELETE method using JavaScript? I want to use a for loop like this:

var node_ids = ["123","456","789"];
var field_ids = ["abc","def","ghi"];

for (i = 0; i < node_ids.length < i++){

// MAKE DELETE REQUEST to ".5/" + node_ids[i] + "/{{EDGE_NAME}}/?field_ids=['" + field_ids[i] + "']";

}

I saw a code like this online that I thought might be applicable, but I don't know how it works...

$.ajax({
    url: '/script.cgi',
    type: 'DELETE',
    success: function(result) {
        console.log(result)
    }
});

It looks like jquery but I guess it must be ajax? Does ajax need a library to be referenced like jquery does? Is it as simple as putting this function inside my for-loop and passing the URL I'm building inside the for loop to the 'url' field in the ajax call...?

What is the best function to pass to the 'success' parameter here so I know my request was successful? Is it possible to return the response from the delete request i.e. success:true if it works?

The more explicit you can be, the better!

Do you foresee any issues with me looping through 8000 entries across two arrays (one contains the node ID / object I am editing, and one contains a field related to the edge I'm accessing which will delete aka 'remove' the assignment from the node I am accessing...?

Thanks!

I work in advertising. I am using the FB graph API to 'DELETE' ad assignments from the platform for a client using the HTTP DELETE method.

My requests are in the format:

https://graph.facebook./v2.5/{{NODE_ID}}/{{EDGE_NAME}}?field_ids=['123456']

I normally use the graph explorer tool (https://developers.facebook./tools/explorer) to acplish such a task, but the client has provided over 8000 assignment to delete so doing it manually one by one would be tough.

How can I invoke an HTTP DELETE method using JavaScript? I want to use a for loop like this:

var node_ids = ["123","456","789"];
var field_ids = ["abc","def","ghi"];

for (i = 0; i < node_ids.length < i++){

// MAKE DELETE REQUEST to "https://graph.facebook./v2.5/" + node_ids[i] + "/{{EDGE_NAME}}/?field_ids=['" + field_ids[i] + "']";

}

I saw a code like this online that I thought might be applicable, but I don't know how it works...

$.ajax({
    url: '/script.cgi',
    type: 'DELETE',
    success: function(result) {
        console.log(result)
    }
});

It looks like jquery but I guess it must be ajax? Does ajax need a library to be referenced like jquery does? Is it as simple as putting this function inside my for-loop and passing the URL I'm building inside the for loop to the 'url' field in the ajax call...?

What is the best function to pass to the 'success' parameter here so I know my request was successful? Is it possible to return the response from the delete request i.e. success:true if it works?

The more explicit you can be, the better!

Do you foresee any issues with me looping through 8000 entries across two arrays (one contains the node ID / object I am editing, and one contains a field related to the edge I'm accessing which will delete aka 'remove' the assignment from the node I am accessing...?

Thanks!

Share Improve this question edited Jan 19, 2016 at 23:48 Kamui asked Jan 19, 2016 at 23:46 KamuiKamui 7991 gold badge9 silver badges17 bronze badges 2
  • 1 $.ajax is jQuery. api.jquery./jquery.ajax – user247702 Commented Jan 19, 2016 at 23:48
  • Please read a bit more online, run through a few tutorials about jQuery and ajax. Right now you have way too many questions here and it is therefore overly broad. Have a look at How to Ask for information. – Heretic Monkey Commented Jan 19, 2016 at 23:49
Add a ment  | 

1 Answer 1

Reset to default 4

It looks like jquery but I guess it must be ajax?

Ajax is a term used to mean "Making an HTTP request, using JavaScript, from a webpage, without leaving the page". There is no way to make a DELETE request from a webpage without using Ajax.

The example code you have uses the jQuery library to achieve it.

Does ajax need a library to be referenced like jquery does?

You need some means to make the HTTP request. JavaScript has nothing for that built in, but most host environments provide at least one mechanism for it. In the case of a web browser, the standard mechanism is XMLHttpRequest. jQuery's Ajax function is a wrapper around that (usually, there are some exceptions, notably when a JSONP request is made).

Is it as simple as putting this function inside my for-loop and passing the URL I'm building inside the for loop to the 'url' field in the ajax call...?

Yes.

What is the best function to pass to the 'success' parameter here so I know my request was successful?

That depends on what you mean by "know" and "successful".

The code you have will log the response to the console if a successful HTTP status was achieved. If you want to be informed by some other mechanism then you'll need to be more more specific.

If the server doesn't give any content in the response or (in the unlikely event of) it doesn't give a sane HTTP status code, then you might need something else.

Is it possible to return the response from the delete request i.e. success:true if it works?

No. Ajax is asynchronous.

本文标签: methodsHow can I make an HTTP DELETE request through JavaScriptStack Overflow