Reputation: 2137
Here is my $.ajax() code, but I can't make it work.
After I change the form from contentType: "text/xml ; ",**
to contentType: "text/xml ; charset=UTF-8",
The request is broken. However, according to the official document: api/$.ajax, I have to do so,or the charset will be same with the server.
var soapRequest_add_a_new_story_to_db=
'<?xml version="1.0" encoding="utf-8"?>'+
'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '+
'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '+
'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'+
'<soap:Body> '+
'<AddNewStory xmlns="http://x.x.x.x/StoryForMac/">'+
'<StoryID>'+story_id+'</StoryID>'+
'<UserName>' +User_Name+ '</UserName>'+
'<Story_CreateTime>'+Edit_Time+'</Story_CreateTime>'+
'<StoryName>'+Story_Name+'</StoryName>'+
'</AddNewStory>'+
'</soap:Body>'+
'</soap:Envelope>';
$.ajax({
type: "POST",
url: webServiceAddNewStoryToDbUrl,
contentType: "text/xml ; charset=UTF-8",
dataType: "xml",
data: soapRequest_add_a_new_story_to_db,
success: processSuccess, //If the SOAP connection sucessess, the function: processSuccess() will be called.
error: processError
});
My another relevant emergent issue Chinese Character doesn't appear. is similar to this one, if available, please take a look.
UPDATE:
Please read this part of the doc,(ctr+f, jump to "processData").
I think my data is already a query string so that I ignore the option:processData. The doc says: "If you want to send a DOMDocument, or other non-processed data, set this option to false." But my soapRequest_add_a_new_story_to_db is not a DOMDocument. And what's the definition of "non-processed" data? Please give explain and relative reference document.
Upvotes: 0
Views: 1074
Reputation: 42414
In your ajax call you have to prevent the processing of your data. You basically tell jquery: "don't touch my request and response data I know what I'm doing." The data in your request var is a valid soap message as is, so you want to prevent that jquery tries to convert it (which it will do for json or xml data).
$.ajax({
type: "POST",
url: webServiceAddNewStoryToDbUrl,
contentType: "text/xml; charset=\"UTF-8\"",
dataType: "xml",
processData: false,
data: soapRequest_add_a_new_story_to_db,
success: processSuccess, //If the SOAP connection sucessess, the function: processSuccess() will be called.
error: processError
});
Upvotes: 1