Since there is no parse.com API to delete a class, how should one delete a class in one call? the recommended way is to delete row by row and then the class is left empty but is there an easier way?
var options = {
method: 'POST',
url: 'https://api.parse.com/1/schemas/' + ___TABLE_NAME___,
body: '{"_ApplicationId":"___APP_ID___","_MasterKey":"___MASTER_KEY___","_ClientVersion":"browser","_method":"DELETE"}',
headers: {
'Pragma': 'no-cache',
'Origin': 'https://www.parse.com',
'Accept-Encoding': 'gzip,deflate',
'Host': 'api.parse.com',
'Accept-Language': 'en-US,en;q=0.8,he;q=0.6',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36',
'Accept': '*/*',
'Cache-Control': 'no-cache',
'Referer': 'https://www.parse.com/apps/COLLECTION_NAME/collections',
'Connection': 'keep-alive',
'Content-Length': '163'
}
};
request(options, function(r,o,t) {
callback();
})
Related
I know there are many questions on SO about this but none of the suggestions have worked for me.
Here is my code:
var restService = "http://wcfrestservice:8004/RADPOCService/WebApp1";
$.ajax({
url: restService,
type: "POST",
data: { PhoneNumber: y },
dataType: "json",
contentType: "application/json; charset=utf-8",
success:
function (data) {
window.open(data.Url, '_blank');
}
});
Fiddler shows my request going across the wire like so (redacted):
POST http://localhost:8004/RADPOCService/WebApp1 HTTP/1.1
Host: localhost:8004
Connection: keep-alive
Content-Length: 22
Accept: application/json, text/javascript; q=0.01
Origin: http://localhost:8000
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36
Content-Type: application/json; charset=UTF-8
Referer: http://localhost:8000/Default.aspx
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.8
Requestor: Me
PhoneNumber=1234567890
I am expecting the payload to look like this:
{ "PhoneNumber": "1234567890"}
When I set the payload as above in the Fiddler Composer tab the service works as expected. What am I doing wrong?
I hate to do this so quickly after posting my question but the answer is to use the JSON.stringify API on the data being sent to the service. So the above should have the following code for 'data' in the ajax call:data: JSON.stringify({ PhoneNumber: y })
I am using ExtJs to create a button that do an ajax post to my django application, but the post is blocked by a FORBIDDEN (403) error.
I tryed to pass the CSRF token in as POST data by setting a custom X-CSRFToken header to the value of the CSRF token (https://docs.djangoproject.com/en/1.3/ref/contrib/csrf/#ajax) without success
ExtJS.js
action = new Ext.Button({
text: 'Ajax Test',
handler: function () {
Ext.Ajax.request({
url: 'test/',
method: 'POST',
headers: { 'Content-Type': 'application/json'},
params: {'test': 'test'},
success: function(response, opts) {
var obj = Ext.decode(response.responseText);
console.dir(obj);
},
failure: function(response, opts) {
console.log('server-side failure');
}
});
},
});
view.py
def test(request):
print "TEST WORKING"
print dict(request.POST.copy().iteritems())
return HttpResponse("")
CHROME NETWORK TAB:
Response:
CSRF verification failed. Request aborted.
Cookies:
Request Cookies:
csrftoken : S7uLgmhqeprWqL4NdH9mznIfpTgyM9RP
djdt : hide
djdttop : 30
sessionid : sx4ukmkitqp39wvuve1a9zed2kjiwfb1
Response Cookies:
(empty)
Headers:
Request URL:http://127.0.0.1:8000/basqui/layer/edit/2/test/
Request Method:POST
Status Code:403 FORBIDDEN
Request Headersview source
Accept:*/*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4
Connection:keep-alive
Content-Length:9
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Cookie:sessionid=sx4ukmkitqp39wvuve1a9zed2kjiwfb1; csrftoken=S7uLgmhqeprWqL4NdH9mznIfpTgyM9RP; djdttop=30; djdt=hide
Host:127.0.0.1:8000
Origin:http://127.0.0.1:8000
Referer:http://127.0.0.1:8000/basqui/layer/edit/2
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36
X-Requested-With:XMLHttpRequest
Form Dataview sourceview URL encoded
test:test
Response Headersview source
Content-Type:text/html
Date:Tue, 07 Jan 2014 16:52:15 GMT
Server:WSGIServer/0.1 Python/2.7.5
X-Frame-Options:SAMEORIGIN
action = new Ext.Button({
text: 'Ajax Test',
handler: function () {
var csrf = Ext.util.Cookies.get('csrftoken');
Ext.Ajax.request({
url: 'test/',
method: 'POST',
headers: { 'Content-Type': 'application/json'},
params: {'test': 'test', 'csrfmiddlewaretoken': csrf},
success: function(response, opts) {
var obj = Ext.decode(response.responseText);
console.dir(obj);
},
failure: function(response, opts) {
console.log('server-side failure');
}
});
},
});
https://www.sencha.com/forum/showthread.php?134125-Django-1-3-Login-with-ExtJS-4-and-CSRF
I put this in my Application launch function:
Ext.require(["Ext.util.Cookies", "Ext.Ajax"], function(){
// Add csrf token to every ajax request
var token = Ext.util.Cookies.get('csrftoken');
if(!token){
Ext.Error.raise("Missing csrftoken cookie");
} else {
Ext.Ajax.defaultHeaders = Ext.apply(Ext.Ajax.defaultHeaders || {}, {
'X-CSRFToken': token
});
}
});
I am using ajax to call a webservice. But when i check the ouput in firebug i get 400 bad request error. Can you please tell me why do i get the error. Why do i get the error. Is anything wrong in following code.Following is the code i have written:
<script>
function HelloWorld() {
var sDate = '<cart currency="USD" total="5.38"><cart-shipment total="5.38" shipment-reference="33261668"><shipment-tax total="0.39" /><shipment-cost total="0" /><shipment-address><address>33 W 59TH STREET APT 203 </address><zip>60559</zip><city>WESTMONT</city><state>IL</state><country>US</country><phone></phone><name>John Baker</name><attention-of>KID</attention-of></shipment-address><items><item total="4.99"><item-name>Hello Kitty - cupcake</item-name><item-description>Hello Kitty - cupcake</item-description><item-price>4.99</item-price><item-quantity>1</item-quantity></item></items></cart-shipment></cart>';
var webMethod = "https://abc.com/Services/TransactionService.svc";
var sr = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:ns2="vp">' +
'<soapenv:Header/>' +
'<soapenv:Body>' +
'<tem:ProcessTransaction>' +
'<tem:checkOutData>' + sDate + '</tem:checkOutData>' +
'<tem:token>5OMc0y1miZN5EFqiZ8IiLn+mzdboyTuTob43Kp4+VcVtrYGQvl7QWJB5OeoPWQpBUej6LSejwE8f16tDhg1EUqDtGGAdn/MM3Gk8MOr0FvFko84ogfhIs9HCUjum2MUN1a/sALjhen+DareUP5wWbIpnu8Eaqg2Tv0RjEsq1bqYblHcXfKIq7anTDzYoHN8Y7LAXgdEhSrVcEIB3+sCCDQ==</tem:token>' +
'<tem:transactionDescription>Volusion Order Description</tem:transactionDescription>' +
'</tem:ProcessTransaction>' +
'</soapenv:Body>' +
'</soapenv:Envelope>';
$.ajax({
type: "POST",
url: webMethod,
data: sr,
contentType: "text/xml",
dataType: "xml",
cache: false,
success: OnSuccess,
error: OnError
});
return false;
}
function OnSuccess(data, status) {
alert(data);
}
function OnError(request, status, error) {
alert(error);
}
</script>
<div>
<input type="button" value="Soap" onclick="HelloWorld();" />
</div>
Following is the output that i receive in firebug:
Request Headers:
OPTIONS /Services/TransactionService.svc?wsdl HTTP/1.1
Host: development.virtualpiggy.com
Connection: keep-alive
Access-Control-Request-Method: POST
Origin: http://test.com
User-Agent: Mozilla/5.0 (Windows NT 6.0) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11
Access-Control-Request-Headers: origin, content-type, accept
Accept: /
Referer: http://test.com/Desktop/test_webservice.htm
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Response Header:
Access-Control-Allow-Origin:http://yann-asus:81 http://www.kkdmarketing.com
Cache-Control:private
Content-Length:0
Date:Tue, 04 Dec 2012 06:42:23 GMT
Server:Microsoft-IIS/7.0
Set-Cookie:SessionId=ovpsrxt33jyoi3pzidvxkh0o; path=/; secure; HttpOnly
X-AspNet-Version:4.0.30319
X-Powered-By:ASP.NET
I would try setting a utf-8 charset in the contentType
$.ajax({
type: "POST",
url: webMethod,
data: sr,
contentType: "text/xml; charset=utf-8",
dataType: "xml",
cache: false,
success: OnSuccess,
error: OnError
});
I know about error in application running on server and invoked operation disconnect all HTTP clients. I need to invoke this functionality on the server but I'm not able to fix the error.
Here is my server code:
<?php
// file: run_script.php
shell_exec('close_all_HTTP_connections_error '.$_REQUEST['params']);
?>
I'm trying to find workaround via AJAX call, I know that call fails, but user doesn't see error like ERR_EMPTY_RESPONSE. My problem is that I need to do another call to the server (which doesn't fail normaly). The second call is not send to server because previous call fail I guess.
Here is my jQuery AJAX call:
function sendData(url, step) {
$.ajax({
type: 'POST',
async: true,
url: url,
headers: { // I try it without this also
'Connection' : 'close'
},
data: {
'params' : 'bla bla'
},
complete: function(jqXHR, textStatus) {
console.log(jqXHR);
console.log(textStatus);
if (step < 2) {
sendData('another.php', step+1);
}
else {
console.log("done");
// go forward
}
},
dataType: 'html'
});
}
$(document).ready(function() {
sendData('run_script.php', 1);
});
Here is my screen shot from Chrome inspector:
And HTTP Requests:
run_script.php:
POST http://?????.com/test/run_script.php HTTP/1.1
Origin: http://?????.com
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.22 (KHTML, like Gecko)
Chrome/19.0.1049.3 Safari/535.22
Content-Type: application/x-www-form-urlencoded
Accept: text/html, */*; q=0.01
Referer: http://?????.com/test/result.php
params:bla bla
another.php:
POST http://?????.com/test/another.php HTTP/1.1
Origin: http://?????.com
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.22 (KHTML, like Gecko)
Chrome/19.0.1049.3 Safari/535.22
Content-Type: application/x-www-form-urlencoded
Accept: text/html, */*; q=0.01
Referer: http://?????.com/test/result.php
params:bla bla
There is no HTTP Response of course.
Problem was, that task previously invoked on server restarts server. Then I need to wait before next AJAX call is invoked.
I fact I have to solve problem with server restart first, this is work-around only and not the best solution.
This is probably something simple, but I just can't see it.
I've got my sencha-touch application posting data to my WebService (asp.net-mvc-3). The Sencha Touch js code looks like this.
var submitCommunicateCard = function () {
console.log(rpc.views.Contact.CommunicateCard.getValues());
Ext.Ajax.request({
url: WebService('GetInTouch', 'CommunicateCard'), //http://webservice.example.com/GetInTouch/CommunicateCard
method: 'post',
params: {
callback: 'foo', //temporary until I can better setup the callback.
name: rpc.views.Contact.CommunicateCard.getValues().name,
city: rpc.views.Contact.CommunicateCard.getValues().city
}
});
};
Since I need to "thwart" my Cross Site Scripting problems, I've had to write an ActionFilter that adds the appropriate headers.
namespace WebService.Attributes
{
public class AllowCrossSiteJsonAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Current.Response.Cache.SetNoStore();
HttpContext.Current.Response.AppendHeader("Access-Control-Allow-Origin", "*");
string rqstMethod = HttpContext.Current.Request.Headers["Access-Control-Request-Method"];
if (rqstMethod == "OPTIONS" || rqstMethod == "POST")
{
HttpContext.Current.Response.AppendHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
HttpContext.Current.Response.AppendHeader("Access-Control-Allow-Headers", "X-Requested-With, Accept, Access-Control-Allow-Origin");
}
}
}
}
And in my controller, I'm receiving the data from my app as follows.
[AllowCrossSiteJsonAttribute]
public JsonpResult CommunicateCard(CommunicateCardModel communicateCardModel)
{
CommunicateCardModel cc = null;
string rqstMethod = System.Web.HttpContext.Current.Request.Headers["Access-Control-Request-Method"];
if (rqstMethod != "POST")
{
// Do stuff with the model
return this.Jsonp(true);
}
else {
return this.Jsonp(false);
}
}
You'll see that I had to put if (rqstMethod != "POST") because the model from the "POST" is blank, but the model from the "OPTIONS" is not.
Here are the raw headers being passed... (note: these two headers are being passed in pairs... ie: the controller is being called twice.)
FIRST CALL
OPTIONS /GetInTouch/CommunicateCard HTTP/1.1
Host: webservice.example.com
Referer: http://192.168.3.138/
Access-Control-Request-Method: POST
Origin: http://192.168.3.138
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_0) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.71 Safari/534.24
Access-Control-Request-Headers: X-Requested-With, Content-Type
Accept: /
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
SECOND CALL (notice the very bottom line that contains the posted data (which is not contained within the first call) callback=foo&name=Chester&city=Toronto)
POST /GetInTouch/CommunicateCard HTTP/1.1
Host: webservice.example.com
Referer: http://192.168.3.138/
Content-Length: 38
Origin: http://192.168.3.138
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_0) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.71 Safari/534.24
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Accept: /
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
callback=foo&name=Chester&city=Toronto
Is there any way to prevent multiple calls to my controller? (or why IS my controller being called twice?)
Turns out it was fixed by making a JSONP call from my Sencha Touch app.
Ext.util.JSONP.request
// THIS IS WRONG, DON'T USE THIS CODE TO MAKE JSONP CALLS
var submitCommunicateCard = function () {
console.log(rpc.views.Contact.CommunicateCard.getValues());
Ext.Ajax.request({
url: WebService('GetInTouch', 'CommunicateCard'), //http://webservice.example.com/GetInTouch/CommunicateCard
method: 'post',
params: {
callback: 'foo', //temporary until I can better setup the callback.
name: rpc.views.Contact.CommunicateCard.getValues().name,
city: rpc.views.Contact.CommunicateCard.getValues().city
}
});
// THIS IS RIGHT
var submitCommunicateCard = function () {
console.log("Outbound Data Object:");
console.log(rpc.views.Contact.CommunicateCard.getValues());
Ext.util.JSONP.request({
url: WebService('GetInTouch', 'CommunicateCard'),
method: 'post',
callbackKey: 'callback',
params: {
name: rpc.views.Contact.CommunicateCard.getValues().name,
city: rpc.views.Contact.CommunicateCard.getValues().city
},
callback: function (result) {
console.log("Inbound Data Object:");
console.log(result);
// Handle error logic
if (result.success === true) {
Ext.Msg.alert("Sent!", "Thank you, your message has been sent!", Ext.emptyFn);
rpc.views.Contact.CommunicateCard.reset();
} else {
Ext.Msg.alert("Oops!", "looks like something went wrong, please try again.", Ext.emptyFn);
}
}
});
};