English 中文(简体)
使用jquery提交表单
原标题:Submit form using jquery

我正在尝试使用JQuery提交表单。我的问题来自于这样一个事实,即前端(html+js/jquery)和后端不在同一个站点上,但它确实支持JSONP。

The form contains a file input field, so I would be submitting Multi-part form data. How would you resolve this?

最佳回答

你的表单操作将指向控制帖子的网站。

<form id="theForm" action="http://someurltoaformsubmitfunction" method="post">

then you can call $( #theForm ).submit();

问题回答

如果你只想提交表单并转到外部网站(即,就好像你在传统的web表单上按下了提交按钮),你可以使用Javascript触发表单的提交方法;表单发布到哪里并不重要。

document.myform.submit();

然而,如果你想使用AJAX类型的方法跨域发布,你会遇到困难。答案在于在你的JQueryAJAX请求中使用JSONP而不是JSON。

请参阅JQuery Ajax文档了解更多详细信息。

编辑:不要尝试此操作,它不适用于跨域帖子我的错是没有足够仔细地阅读这个问题。

它必须是提交的表格吗?如果没有,您可以简单地执行一个jQueryajax调用,向其发布json,类似于以下内容:

$.ajax({
    url:  yourUrl.htm ,
    data:  somethingYouWantToSendToQueryString ,
    datatype:  json ,
    success: function (data) {
        //Do something with the data
    }
});




相关问题
How can I load a folders files into a ListView?

I d like to have a user select a folder with the FolderBrowserDialog and have the files loaded into the ListView. My intention is to make a little playlist of sorts so I have to modify a couple of ...

File Handling Issue

I am developing a tool in c#, at one instance I start writing into a xml file continuously using my tool,when i suddenly restart my machine the particular xml file gets corrupted, what is the reason ...

C# GemBox Excel Import Error

I am trying to import an excel file into a data table using GemBox and I keep getting this error: Invalid data value when extracting to DataTable at SourceRowIndex: 1, and SourceColumnIndex: 1. As ...

Saving output of a for-loop to file

I have opened a file with blast results and printed out the hits in fasta format to the screen. The code looks like this: result_handle = open("/Users/jonbra/Desktop/my_blast.xml") from Bio.Blast ...

热门标签